Exemplo n.º 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);
        }
Exemplo n.º 2
0
        internal void DiscoverAndRun()
        {
            var assembly = typeof(R2APITest).Assembly;
            var path     = assembly.Location;

            R2APITest.Logger.LogInfo($"Discovering tests in {path}...");
            var assemblyElement = new XElement("assembly");

            try {
                var messageSink = new MessageSink {
                    OnTest = OnTest,
                    OnExecutionComplete = OnExecutionComplete,
                };

                using (
                    var controller = new XunitFrontController(
                        AppDomainSupport.Denied,
                        path
                        )
                    ) {
                    var configuration = ConfigReader.Load(path);
                    configuration.AppDomain              = AppDomainSupport.IfAvailable;
                    configuration.DiagnosticMessages     = true;
                    configuration.StopOnFail             = true;
                    configuration.MaxParallelThreads     = 1;
                    configuration.LongRunningTestSeconds = 5;
                    ITestFrameworkDiscoveryOptions discoveryOptions =
                        TestFrameworkOptions.ForDiscovery(configuration);
                    discoveryOptions.SetSynchronousMessageReporting(true);
                    discoveryOptions.SetPreEnumerateTheories(false);
                    controller.Find(false, messageSink, discoveryOptions);
                    messageSink.DiscoveryCompletionWaitHandle.WaitOne();
                    ITestCase[] testCases = messageSink.TestCases.ToArray();
                    lock (this) {
                        R2APITest.Logger.LogInfo(
                            $"{testCases.Length} test cases were found in {path}:"
                            );
                        foreach (ITestCase testCase in testCases)
                        {
                            R2APITest.Logger.LogInfo($"- {testCase.DisplayName}");
                        }

                        Console.Error.Flush();
                    }

                    ITestFrameworkExecutionOptions executionOptions =
                        TestFrameworkOptions.ForExecution(configuration);
                    executionOptions.SetDiagnosticMessages(true);
                    executionOptions.SetSynchronousMessageReporting(true);
                    executionOptions.SetStopOnTestFail(true);
                    executionOptions.SetDisableParallelization(true);

                    controller.RunTests(
                        testCases,
                        messageSink,
                        executionOptions
                        );
                    messageSink.ExecutionCompletionWaitHandle.WaitOne();
                }
            }
            catch (Exception e) {
                R2APITest.Logger.LogError($"{e.GetType().Name}: {e.Message}");
                R2APITest.Logger.LogError(e.StackTrace);
            }
            R2APITest.Logger.LogInfo($"All tests in {path} ran.");
        }