NUnit.VisualStudio.TestAdapter.AssemblyRunner.RunAssembly C# (CSharp) Method

RunAssembly() public method

public RunAssembly ( IFrameworkHandle testLog ) : void
testLog IFrameworkHandle
return void
        public void RunAssembly(IFrameworkHandle testLog)
        {
            try
            {
            #if LAUNCHDEBUGGER
            System.Diagnostics.Debugger.Launch();
            #endif
                if (TryLoadAssembly())
                {
                    using (NUnitEventListener listener = new NUnitEventListener(testLog, TestConverter))
                    {
                        try
                        {
                            runner.Run(listener, NUnitFilter, true, LoggingThreshold.Off);
                        }
                        catch (NullReferenceException)
                        {
                            // this happens during the run when CancelRun is called.
                            logger.SendDebugMessage("Nullref caught");
                        }
                        finally
                        {
                            runner.Unload();
                        }
                    }
                }
                else
                {
                    logger.NoNUnit2TestsFoundIn(assemblyName);
                }
            }
            catch (BadImageFormatException)
            {
                // we skip the native c++ binaries that we don't support.
                logger.AssemblyNotSupportedWarning(assemblyName);
            }
            catch (System.IO.FileNotFoundException ex)
            {
                // Probably from the GetExportedTypes in NUnit.core, attempting to find an assembly, not a problem if it is not NUnit here
                logger.DependentAssemblyNotFoundWarning(ex.FileName, assemblyName);
            }
            catch (UnsupportedFrameworkException ex)
            {
                //The UnsupportedFrameworkException is thrown by nunit, if the assembly references the NUnit v3 framework.
                logger.SendInformationalMessage("Attempt to load assembly with unsupported test framework in " +  assemblyName);
            }
            catch (Exception ex)
            {
                logger.SendErrorMessage("Exception thrown executing tests in " + assemblyName, ex);
            }
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Called by the VisualStudio IDE when selected tests are to be run. Never called from TFS Build.
        /// </summary>
        /// <param name="tests">The tests to be run</param>
        /// <param name="runContext">The RunContext</param>
        /// <param name="frameworkHandle">The FrameworkHandle</param>
        public void RunTests(IEnumerable <TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
#if LAUNCHDEBUGGER
            Debugger.Launch();
#endif

            TestLog.Initialize(frameworkHandle);
            if (RegistryFailure)
            {
                TestLog.SendErrorMessage(ErrorMsg);
            }
            var enableShutdown = (UseVsKeepEngineRunning) ? !runContext.KeepAlive : true;
            frameworkHandle.EnableShutdownAfterTestRun = enableShutdown;
            Debug("executing tests", "EnableShutdown set to " + enableShutdown);
            Info("executing tests", "started");

            // Ensure any channels registered by other adapters are unregistered
            CleanUpRegisteredChannels();

            var assemblyGroups = tests.GroupBy(tc => tc.Source);
            foreach (var assemblyGroup in assemblyGroups)
            {
                currentRunner = new AssemblyRunner(TestLog, assemblyGroup.Key, assemblyGroup, this);
                currentRunner.RunAssembly(frameworkHandle);
            }

            Info("executing tests", "finished");
        }
All Usage Examples Of NUnit.VisualStudio.TestAdapter.AssemblyRunner::RunAssembly