Beispiel #1
0
        private static ITestFrameworkExecutionOptions ConfiguExecutionOptions([NotNull] XunitProjectAssembly assembly, [NotNull] TestRunOptions options)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            bool stopOnFail = options.StopOnFail;

            ITestFrameworkExecutionOptions executionOptions = TestFrameworkOptions.ForExecution(assembly.Configuration);

            executionOptions.SetStopOnTestFail(stopOnFail);

            int?maxThreadCount = options.MaxParallelThreads;

            if (maxThreadCount.HasValue)
            {
                executionOptions.SetMaxParallelThreads(maxThreadCount);
            }

            bool?parallelizeTestCollections = options.ParallelizeTestCollections;

            if (parallelizeTestCollections.HasValue)
            {
                executionOptions.SetDisableParallelization(!parallelizeTestCollections.GetValueOrDefault());
            }

            return(executionOptions);
        }
Beispiel #2
0
    private async Task <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()
                {
                    PreEnumerateTheories = false
                };
                ITestFrameworkDiscoveryOptions discoveryOptions = GetFrameworkOptionsForDiscovery(configuration);
                discoveryOptions.SetSynchronousMessageReporting(true);
                Logger.OnDebug($"Starting test discovery in the '{assembly}' assembly");
                frontController.Find(false, discoverySink, discoveryOptions);
                Logger.OnDebug($"Test discovery in assembly '{assembly}' completed");
                discoverySink.Finished.WaitOne();

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

                TotalTests += discoverySink.TestCases.Count;
                List <ITestCase> testCases;
                if (_filters != null && _filters.TestCaseFilters.Any())
                {
                    Action <string> log = LogExcludedTests ? (s) => do_log(s) : (Action <string>)null;
                    testCases = discoverySink.TestCases.Where(
                        tc => !_filters.IsExcluded(tc, log)).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);
                executionOptions.SetMaxParallelThreads(MaxParallelThreads);

                // set the wait for event cb first, then execute the tests
                var resultTask = WaitForEvent(resultsSink.Finished, TimeSpan.FromDays(10)).ConfigureAwait(false);
                frontController.RunTests(testCases, resultsSink, executionOptions);
                await resultTask;

                return(assemblyElement);
            }
        }
    }