/// <summary> /// Creates a new TestPage visual that in turn will setup and begin a /// unit test run. /// </summary> /// <param name="settings">Test harness settings to be applied.</param> /// <returns>A new RootVisual.</returns> /// <remarks>Assumes the calling assembly is a test assembly.</remarks> public static UIElement CreateTestPage(UnitTestSettings settings) { UnitTestSystem system = new UnitTestSystem(); Type testPageType = typeof(TestPage); Type testPageInterface = typeof(ITestPage); if (settings.TestPanelType != null && testPageInterface.IsAssignableFrom(settings.TestPanelType)) { testPageType = settings.TestPanelType; } object testPage; try { // Try creating with an instance of the test harness testPage = Activator.CreateInstance(testPageType, settings.TestHarness); } catch { // Fall back to a standard instance only testPage = Activator.CreateInstance(testPageType); } PrepareTestService(settings, () => system.Run(settings)); // NOTE: A silent failure would be if the testPanel is not a // UIElement, and it returns anyway. return testPage as UIElement; }
public void Run(UnitTestSettings settings) { // Avoid having the Run method called twice if (_harness != null) { return; } _harness = settings.TestHarness; if (_harness == null) { throw new InvalidOperationException(Properties.UnitTestMessage.UnitTestSystem_Run_NoTestHarnessInSettings); } if (settings.TestService == null && !settings.TestServiceSetterCalled) { SetTestService(settings); } _harness.Settings = settings; _harness.TestHarnessCompleted += (sender, args) => OnTestHarnessCompleted(args); if (settings.StartRunImmediately) { _harness.Run(); } }
/// <summary> /// A partial method for PrepareDefaultLogManager. /// </summary> /// <param name="settings">The test harness settings.</param> public static void PrepareCustomLogProviders(UnitTestSettings settings) { // TODO: Consider what to do on this one... // Should probably update to use the newer log system with events, // and then after that figure out when it applies... perhaps only // when someone first requests to use it. ////if (HtmlPage.IsEnabled) ////{ ////settings.LogProviders.Add(new TextFailuresLogProvider()); ////} }
/// <summary> /// Initializes the test service and its contained providers. /// </summary> /// <param name="inputSettings">The run settings.</param> /// <param name="complete">Action to call once the test service is /// initialized and ready to continue the run's execution.</param> private static void PrepareTestService(UnitTestSettings inputSettings, Action complete) { TestServiceProvider testService = inputSettings.TestService; if (testService != null && testService.Initialized == false) { Action after = delegate { MergeSettingsAndParameters(testService, inputSettings); complete(); }; testService.InitializeCompleted += delegate(object sender, EventArgs e) { after(); }; testService.Initialize(); } else { complete(); } }
/// <summary> /// Tries to instantiate and initialize a VSTT provider. Requires that /// XLinq is available and included in the application package. /// </summary> /// <param name="settings">The test harness settings object.</param> private static void TryAddVisualStudioLogProvider(UnitTestSettings settings) { VisualStudioLogProvider trx = new VisualStudioLogProvider(); settings.LogProviders.Add(trx); }
/// <summary> /// Create a default settings object for unit testing. /// </summary> /// <param name="callingAssembly">The assembly reflection object.</param> /// <returns>A unit test settings instance.</returns> private static UnitTestSettings CreateDefaultSettings(Assembly callingAssembly) { UnitTestSettings settings = new UnitTestSettings(); if (callingAssembly != null) { settings.TestAssemblies.Add(callingAssembly); } SetStandardLogProviders(settings); settings.TestHarness = new UnitTestHarness(); // Sets initial but user can override SetTestService(settings); return settings; }
/// <summary> /// Prepares the default log manager. /// </summary> /// <param name="settings">The test harness settings.</param> public static void SetStandardLogProviders(UnitTestSettings settings) { // Debug provider DebugOutputProvider debugger = new DebugOutputProvider(); debugger.ShowAllFailures = true; settings.LogProviders.Add(debugger); // Visual Studio log provider try { TryAddVisualStudioLogProvider(settings); } catch { } PrepareCustomLogProviders(settings); }
/// <summary> /// Creates a new TestPage visual that in turn will setup and begin a /// unit test run. /// </summary> /// <returns>A new RootVisual.</returns> /// <remarks>Assumes the calling assembly is a test assembly.</remarks> public static UIElement CreateTestPage() { UnitTestSettings settings = CreateDefaultSettings(Assembly.GetCallingAssembly()); return(CreateTestPage(settings)); }
/// <summary> /// A partial method for setting the TestService. /// </summary> /// <param name="settings">The test harness settings.</param> public static void SetTestService(UnitTestSettings settings) { // REVIEW Following line commented because TestService need to be reviewed. //settings.TestService = new WindowsPhoneTestService(settings); }
/// <summary> /// Merge any settings provided by a test service with the parameters /// that were passed inside the TestHarnessSettings. /// </summary> /// <param name="testService">The test service.</param> /// <param name="inputSettings">The run settings.</param> private static void MergeSettingsAndParameters(TestServiceProvider testService, UnitTestSettings inputSettings) { if (testService != null && testService.HasService(TestServiceFeature.RunSettings)) { SettingsProvider settings = testService.GetService <SettingsProvider>(TestServiceFeature.RunSettings); foreach (string key in settings.Settings.Keys) { if (inputSettings.Parameters.ContainsKey(key)) { Debug.WriteLine("MergeSettingsAndParameters: Overwriting " + key + " key during merge."); } inputSettings.Parameters[key] = settings.Settings[key]; } } }
/// <summary> /// Merge any settings provided by a test service with the parameters /// that were passed inside the TestHarnessSettings. /// </summary> /// <param name="testService">The test service.</param> /// <param name="inputSettings">The run settings.</param> private static void MergeSettingsAndParameters(TestServiceProvider testService, UnitTestSettings inputSettings) { if (testService != null && testService.HasService(TestServiceFeature.RunSettings)) { SettingsProvider settings = testService.GetService<SettingsProvider>(TestServiceFeature.RunSettings); foreach (string key in settings.Settings.Keys) { if (inputSettings.Parameters.ContainsKey(key)) { Debug.WriteLine("MergeSettingsAndParameters: Overwriting " + key + " key during merge."); } inputSettings.Parameters[key] = settings.Settings[key]; } } }