Exemplo n.º 1
0
        XElement Run(Assembly assembly, string assemblyPath)
        {
            using (var frontController = new XunitFrontController(AppDomainSupport, assemblyPath, null, false))
            {
                using (var discoverySink = new TestDiscoverySink())
                {
                    var configuration = GetConfiguration(assembly) ?? new TestAssemblyConfiguration();
                    ITestFrameworkDiscoveryOptions discoveryOptions = GetFrameworkOptionsForDiscovery(configuration);
                    discoveryOptions.SetSynchronousMessageReporting(true);
                    Logger.OnInfo(LogTag, $"Starting test discovery in the '{assembly}' assembly");
                    frontController.Find(false, discoverySink, discoveryOptions);
                    Logger.OnInfo(LogTag, $"Test discovery in assembly '{assembly}' completed");
                    discoverySink.Finished.WaitOne();

                    if (discoverySink.TestCases == null || discoverySink.TestCases.Count == 0)
                    {
                        Logger.OnInfo(LogTag, "No test cases discovered");
                        return(null);
                    }

                    TotalTests += discoverySink.TestCases.Count;
                    List <ITestCase> testCases;
                    if (filters != null && filters.Count > 0)
                    {
                        testCases      = discoverySink.TestCases.Where(tc => IsIncluded(tc)).ToList();
                        FilteredTests += discoverySink.TestCases.Count - testCases.Count;
                    }
                    else
                    {
                        testCases = discoverySink.TestCases;
                    }

                    var            assemblyElement = new XElement("assembly");
                    IExecutionSink resultsSink     = new DelegatingExecutionSummarySink(messageSink, null, null);
                    resultsSink = new DelegatingXmlCreationSink(resultsSink, assemblyElement);
                    ITestFrameworkExecutionOptions executionOptions = GetFrameworkOptionsForExecution(configuration);
                    executionOptions.SetDisableParallelization(!RunInParallel);
                    executionOptions.SetSynchronousMessageReporting(true);

                    try
                    {
                        frontController.RunTests(testCases, resultsSink, executionOptions);
                        resultsSink.Finished.WaitOne();
                    }
                    finally
                    {
                        resultsSink.Dispose();
                    }

                    return(assemblyElement);
                }
            }
        }
 public void Dispose()
 {
     xmlCreationSink?.Dispose();
     executionSummarySink?.Dispose();
 }