Ejemplo n.º 1
0
        static int RunTests(CommandLine commandLine)
        {
            var testRunner = TestRunner.Create(debugEnabled: commandLine.Debug);

            if (commandLine.Trace)
            {
                ChutzpahTracer.AddFileListener();
            }

            var chutzpahAssemblyName = testRunner.GetType().Assembly.GetName();


            Console.WriteLine();
            Console.WriteLine("chutzpah.dll:     Version {0}", chutzpahAssemblyName.Version);
            Console.WriteLine();

            TestCaseSummary testResultsSummary = null;

            try
            {
                var callback = commandLine.TeamCity
                                ? (ITestMethodRunnerCallback) new TeamCityConsoleRunnerCallback()
                                : new StandardConsoleRunnerCallback(commandLine.Silent, commandLine.VsOutput, commandLine.ShowFailureReport);

                callback = new ParallelRunnerCallbackAdapter(callback);

                var testOptions = new TestOptions
                {
                    OpenInBrowser = commandLine.OpenInBrowser,
                    TestFileTimeoutMilliseconds = commandLine.TimeOutMilliseconds,
                    MaxDegreeOfParallelism      = commandLine.Parallelism,
                    TestingMode     = commandLine.TestMode,
                    CoverageOptions = new CoverageOptions
                    {
                        Enabled         = commandLine.Coverage,
                        IncludePatterns = (commandLine.CoverageIncludePatterns ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries),
                        ExcludePatterns = (commandLine.CoverageExcludePatterns ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                    }
                };

                if (!commandLine.Discovery)
                {
                    testResultsSummary = testRunner.RunTests(commandLine.Files, testOptions, callback);
                    ProcessTestSummaryTransformers(commandLine, testResultsSummary);
                }
                else
                {
                    Console.WriteLine("Test Discovery");
                    var tests = testRunner.DiscoverTests(commandLine.Files, testOptions).ToList();
                    Console.WriteLine("\nDiscovered {0} tests", tests.Count);

                    foreach (var test in tests)
                    {
                        Console.WriteLine("Test '{0}:{1}' from '{2}'", test.ModuleName, test.TestName, test.InputTestFile);
                    }
                    return(0);
                }
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }

            var failedCount = testResultsSummary.FailedCount;

            if (commandLine.FailOnError && testResultsSummary.Errors.Any())
            {
                return(failedCount > 0 ? failedCount : 1);
            }

            return(failedCount);
        }