public void Initialize(IRunContext runContext, IFrameworkHandle frameworkHandle) { base.Initialize(runContext, frameworkHandle); TestLog.Info(string.Format("NUnit Adapter {0}: Test execution started", AdapterVersion)); RunContext = runContext; FrameworkHandle = frameworkHandle; TfsFilter = new TfsTestFilter(runContext); // Ensure any channels registered by other adapters are unregistered CleanUpRegisteredChannels(); TestLog.Debug("Keepalive: " + runContext.KeepAlive); TestLog.Debug("UseVsKeepEngineRunning: " + Settings.UseVsKeepEngineRunning); bool enableShutdown = true; if (Settings.UseVsKeepEngineRunning) { enableShutdown = !runContext.KeepAlive; } if (TfsFilter.IsEmpty) { if (!(enableShutdown && !runContext.KeepAlive)) // Otherwise causes exception when run as commandline, illegal to enableshutdown when Keepalive is false, might be only VS2012 { frameworkHandle.EnableShutdownAfterTestRun = enableShutdown; } } TestLog.Debug("EnableShutdown: " + enableShutdown.ToString()); }
public TestFilter ConvertTfsFilterToNUnitFilter(TfsTestFilter tfsFilter, List <TestCase> loadedTestCases) { var filteredTestCases = tfsFilter.CheckFilter(loadedTestCases); var testCases = filteredTestCases as TestCase[] ?? filteredTestCases.ToArray(); //TestLog.Info(string.Format("TFS Filter detected: LoadedTestCases {0}, Filterered Test Cases {1}", loadedTestCases.Count, testCases.Count())); return(MakeTestFilter(testCases)); }
/// <summary> /// Called by the Visual Studio IDE to run all tests. Also called by TFS Build /// to run either all or selected tests. In the latter case, a filter is provided /// as part of the run context. /// </summary> /// <param name="sources">Sources to be run.</param> /// <param name="runContext">Context to use when executing the tests.</param> /// <param name="frameworkHandle">Test log to send results and messages through</param> public void RunTests(IEnumerable <string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle) { #if LAUNCHDEBUGGER if (!Debugger.IsAttached) { Debugger.Launch(); } #endif Initialize(frameworkHandle); try { _tfsFilter = new TfsTestFilter(runContext); TestLog.SendDebugMessage("Keepalive:" + runContext.KeepAlive); var enableShutdown = (UseVsKeepEngineRunning) ? !runContext.KeepAlive : true; if (!_tfsFilter.HasTfsFilterValue) { if (!(enableShutdown && !runContext.KeepAlive)) // Otherwise causes exception when run as commandline, illegal to enableshutdown when Keepalive is false, might be only VS2012 { frameworkHandle.EnableShutdownAfterTestRun = enableShutdown; } } foreach (var source in sources) { var assemblyName = source; if (!Path.IsPathRooted(assemblyName)) { assemblyName = Path.Combine(Environment.CurrentDirectory, assemblyName); } TestLog.SendInformationalMessage("Running all tests in " + assemblyName); RunAssembly(assemblyName, frameworkHandle); } } catch (Exception ex) { if (ex is TargetInvocationException) { ex = ex.InnerException; } TestLog.SendErrorMessage("Exception thrown executing tests", ex); } finally { Info("executing tests", "finished"); Unload(); } }
/// <summary> /// Called by the Visual Studio IDE to run all tests. Also called by TFS Build /// to run either all or selected tests. In the latter case, a filter is provided /// as part of the run context. /// </summary> /// <param name="sources">Sources to be run.</param> /// <param name="runContext">Context to use when executing the tests.</param> /// <param name="frameworkHandle">Test log to send results and messages through</param> public void RunTests(IEnumerable <string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle) { TestLog.Initialize(frameworkHandle); if (RegistryFailure) { TestLog.SendErrorMessage(ErrorMsg); } Info("executing tests", "started"); try { // Ensure any channels registered by other adapters are unregistered CleanUpRegisteredChannels(); var tfsfilter = new TfsTestFilter(runContext); TestLog.SendDebugMessage("Keepalive:" + runContext.KeepAlive); var enableShutdown = (UseVsKeepEngineRunning) ? !runContext.KeepAlive : true; if (!tfsfilter.HasTfsFilterValue) { if (!(enableShutdown && !runContext.KeepAlive)) // Otherwise causes exception when run as commandline, illegal to enableshutdown when Keepalive is false, might be only VS2012 { frameworkHandle.EnableShutdownAfterTestRun = enableShutdown; } } foreach (var source in sources) { string sourceAssembly = source; if (!Path.IsPathRooted(sourceAssembly)) { sourceAssembly = Path.Combine(Environment.CurrentDirectory, sourceAssembly); } using (currentRunner = new AssemblyRunner(TestLog, sourceAssembly, tfsfilter, this)) { currentRunner.RunAssembly(frameworkHandle); } currentRunner = null; } } catch (Exception ex) { TestLog.SendErrorMessage("Exception thrown executing tests", ex); } finally { Info("executing tests", "finished"); } }
// NOTE: an earlier version of this code had a FilterBuilder // property. This seemed to make sense, because we instantiate // it in two different places. However, the existence of an // NUnitTestFilterBuilder, containing a reference to an engine // service caused our second-level tests of the test executor // to throw an exception. So if you consider doing this, beware! #endregion #region ITestExecutor Implementation /// <summary> /// Called by the Visual Studio IDE to run all tests. Also called by TFS Build /// to run either all or selected tests. In the latter case, a filter is provided /// as part of the run context. /// </summary> /// <param name="sources">Sources to be run.</param> /// <param name="runContext">Context to use when executing the tests.</param> /// <param name="frameworkHandle">Test log to send results and messages through</param> public void RunTests(IEnumerable <string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle) { #if LAUNCHDEBUGGER if (!Debugger.IsAttached) { Debugger.Launch(); } #endif TfsFilter = new TfsTestFilter(runContext); Initialize(runContext, frameworkHandle); TestLog.Info($"NUnit Adapter {AdapterVersion}: Test execution request received for { sources?.Count().ToString() } sources"); if (Settings.InProcDataCollectorsAvailable && sources.Count() > 1) { TestLog.Error("Failed to run tests for multiple assemblies when InProcDataCollectors specified in run configuration."); Unload(); return; } foreach (var assemblyName in sources) { try { var assemblyPath = Path.IsPathRooted(assemblyName) ? assemblyName : Path.Combine(Directory.GetCurrentDirectory(), assemblyName); RunAssembly(assemblyPath, null, TestFilter.Empty); } catch (Exception ex) { if (ex is TargetInvocationException) { ex = ex.InnerException; } TestLog.Warning("Exception thrown executing tests", ex); } } TestLog.Info($"NUnit Adapter {AdapterVersion}: Test execution complete"); Unload(); }
/// <summary> /// Called by the Visual Studio IDE to run all tests. Also called by TFS Build /// to run either all or selected tests. In the latter case, a filter is provided /// as part of the run context. /// </summary> /// <param name="sources">Sources to be run.</param> /// <param name="runContext">Context to use when executing the tests.</param> /// <param name="frameworkHandle">Test log to send results and messages through</param> public void RunTests(IEnumerable <string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle) { TestLog.Initialize(frameworkHandle); if (RegistryFailure) { TestLog.SendErrorMessage(ErrorMsg); } Info("executing tests", "started"); try { // Ensure any channels registered by other adapters are unregistered CleanUpRegisteredChannels(); var tfsfilter = new TfsTestFilter(runContext); TestLog.SendDebugMessage("Keepalive:" + runContext.KeepAlive); var enableShutdown = (UseVsKeepEngineRunning) ? !runContext.KeepAlive : true; if (!tfsfilter.HasTfsFilterValue) { frameworkHandle.EnableShutdownAfterTestRun = enableShutdown; } foreach (var source in sources) { using (currentRunner = new AssemblyRunner(TestLog, source, tfsfilter)) { currentRunner.RunAssembly(frameworkHandle); } currentRunner = null; } } catch (Exception ex) { TestLog.SendErrorMessage("Exception thrown executing tests", ex); } finally { Info("executing tests", "finished"); } }