Exemple #1
0
        public void InitializeForExecution(IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            TestLog.Info($"NUnit Adapter {AdapterVersion}: Test execution started");

            RunContext      = runContext;
            FrameworkHandle = frameworkHandle;
            VsTestFilter    = VsTestFilterFactory.CreateVsTestFilter(Settings, runContext);

            CleanUpRegisteredChannels();

            TestLog.Debug("KeepAlive: " + runContext.KeepAlive);
            TestLog.Debug("UseVsKeepEngineRunning: " + Settings.UseVsKeepEngineRunning);

            bool enableShutdown = true;

            if (Settings.UseVsKeepEngineRunning)
            {
                enableShutdown = !runContext.KeepAlive;
            }

            if (VsTestFilter.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);
        }
Exemple #2
0
        // 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
            Initialize(runContext, frameworkHandle);
            TestLog.Debug("RunTests by IEnumerable<string>");
            InitializeForExecution(runContext, frameworkHandle);

            if (Settings.InProcDataCollectorsAvailable && sources.Count() > 1)
            {
                TestLog.Error("Failed to run tests for multiple assemblies when InProcDataCollectors specified in run configuration.");
                Unload();
                return;
            }

            SetRunTypeByStrings();
            var        builder = CreateTestFilterBuilder();
            TestFilter filter  = null;
            if (RunType == RunType.CommandLineCurrentNUnit)
            {
                var vsTestFilter = VsTestFilterFactory.CreateVsTestFilter(Settings, runContext);
                filter = builder.ConvertVsTestFilterToNUnitFilter(vsTestFilter);
            }
            if (filter == null)
            {
                filter = builder.FilterByWhere(Settings.Where);
            }

            foreach (string assemblyName in sources)
            {
                try
                {
                    string assemblyPath = Path.IsPathRooted(assemblyName) ? assemblyName : Path.Combine(Directory.GetCurrentDirectory(), assemblyName);
                    RunAssembly(assemblyPath, null, filter);
                }
                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();
        }