Пример #1
0
        protected override bool Visit(ITestCaseDiscoveryMessage testCaseDiscovered)
        {
            if (testCaseDiscovered.TestCases != null)
            {
                foreach (var testCase in testCaseDiscovered.TestCases)
                {
                    _sink.SendTest(testCase.ToTest());
                }
            }
            else
            {
                _sink.SendTest(testCaseDiscovered.TestCase.ToTest());
            }

            return(base.Visit(testCaseDiscovered));
        }
Пример #2
0
        void ExecuteAssembly(object consoleLock, string assemblyName, CommandLine options)
        {
            if (cancel)
            {
                return;
            }

            try
            {
                var name             = new AssemblyName(assemblyName);
                var assembly         = Reflector.Wrap(Assembly.Load(name));
                var framework        = GetFramework(assembly);
                var discoverer       = framework.GetDiscoverer(assembly);
                var executor         = framework.GetExecutor(name);
                var discoveryVisitor = new TestDiscoveryVisitor();

                discoverer.Find(includeSourceInformation: true, messageSink: discoveryVisitor, options: new TestFrameworkOptions());
                discoveryVisitor.Finished.WaitOne();

                if (options.List)
                {
                    ITestDiscoverySink discoverySink = null;
                    if (options.DesignTime)
                    {
                        discoverySink = (ITestDiscoverySink)_services.GetService(typeof(ITestDiscoverySink));
                    }

                    lock (consoleLock)
                    {
                        foreach (var test in discoveryVisitor.TestCases)
                        {
                            if (discoverySink != null)
                            {
                                discoverySink.SendTest(test.ToDesignTimeTest());
                            }

                            Console.WriteLine(test.DisplayName);
                        }
                    }

                    return;
                }

                var executionOptions = new XunitExecutionOptions {
                    DisableParallelization = !options.ParallelizeTestCollections, MaxParallelThreads = options.MaxParallelThreads
                };
                var resultsVisitor = CreateVisitor(consoleLock, options);

                var tests = discoveryVisitor.TestCases;
                if (options.Tests != null && options.Tests.Count > 0)
                {
                    tests = tests.Where(t => IsTestNameMatch(t, options.Tests)).ToList();
                }

                executor.RunTests(tests, resultsVisitor, executionOptions);
                resultsVisitor.Finished.WaitOne();

                // When executing under TeamCity, we record the results in a format TeamCity understands, but do not return an error code.
                // This causes TeamCity to treat the step as completed, but the build as failed. We'll work around this by special casing the TeamCityVisitor
                var teamCityVisitor = resultsVisitor as TeamCityVisitor;
                if (teamCityVisitor != null)
                {
                    failed = teamCityVisitor.Failed > 0;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0}: {1}", ex.GetType().FullName, ex.Message);
                Console.WriteLine(ex);

                failed = true;
            }
        }