Exemplo 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);
        }
Exemplo n.º 2
0
        static int RunTests(CommandLine commandLine, IEnumerable <SummaryTransformer> transformers)
        {
            var testRunner = TestRunner.Create(debugEnabled: commandLine.Debug);

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


            Console.WriteLine();

            TestCaseSummary testResultsSummary = null;

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

                callback = new ParallelRunnerCallbackAdapter(callback);

                var testOptions = new TestOptions
                {
                    TestLaunchMode                   = commandLine.OpenInBrowser ? TestLaunchMode.FullBrowser : TestLaunchMode.HeadlessBrowser,
                    Engine                           = commandLine.Engine,
                    OpenInBrowserName                = commandLine.BrowserName,
                    OpenInBrowserArgs                = commandLine.BrowserArgs,
                    TestFileTimeoutMilliseconds      = commandLine.TimeOutMilliseconds,
                    ChutzpahSettingsFileEnvironments = commandLine.SettingsFileEnvironments,
                    Proxy           = commandLine.Proxy,
                    CoverageOptions = new CoverageOptions
                    {
                        Enabled         = commandLine.Coverage,
                        IncludePatterns = (commandLine.CoverageIncludePatterns ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries),
                        ExcludePatterns = (commandLine.CoverageExcludePatterns ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries),
                        IgnorePatterns  = (commandLine.CoverageIgnorePatterns ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                    }
                };

                if (commandLine.Parallelism > 0)
                {
                    testOptions.MaxDegreeOfParallelism = commandLine.Parallelism;
                }

                if (!commandLine.Discovery)
                {
                    testResultsSummary = testRunner.RunTests(commandLine.Files, testOptions, callback);
                    ProcessTestSummaryTransformers(transformers, 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.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message);
                Console.ResetColor();
            }

            if (testRunner.ActiveWebServerHost != null)
            {
                Console.WriteLine("Press any key to end Chutzpah...");
                Console.ReadKey();
                testRunner.ActiveWebServerHost.Dispose();
            }


            var failedCount = testResultsSummary.FailedCount;

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


            return(failedCount);
        }