Ejemplo n.º 1
0
        internal static void RunTestProject(this XunitProject project, bool displaySuccess, bool displayFailureStack)
        {
            var mate = new MultiAssemblyTestEnvironment();
            var tests = project.Assemblies.Select(x => mate.Load(x.AssemblyFilename, x.ConfigFilename, x.ShadowCopy));

            var totalAssemblies = 0;
            var totalTests = 0;
            var totalFailures = 0;
            var totalSkips = 0;
            var totalTime = 0.0;

            foreach (var test in tests)
            {
                Console.WriteLine();
                Console.WriteLine("Test assembly: {0}", test.AssemblyFilename);
                Console.WriteLine();

                try
                {
                    var methods = test.EnumerateTestMethods(project.Filters.Filter).ToList();

                    if (!methods.Any())
                    {
                        Console.WriteLine("Skipping assembly (no tests match the specified filter).");
                    }
                    else
                    {
                        var callback = new DefaultRunnerCallback(displaySuccess, displayFailureStack, methods.Count);
                        test.Run(methods, callback);

                        ++totalAssemblies;
                        totalTests += callback.TotalTests;
                        totalFailures += callback.TotalFailures;
                        totalSkips += callback.TotalSkips;
                        totalTime += callback.TotalTime;
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message.Red());
                }

                mate.Unload(test);
            }

            if (totalAssemblies <= 1)
            {
                return;
            }

            Console.WriteLine();
            Console.WriteLine("=== {0} total, {1} failed, {2} skipped, took {3} seconds ===",
                totalTests, totalFailures, totalSkips, totalTime.ToString("0.000", CultureInfo.InvariantCulture));
        }
Ejemplo n.º 2
0
        static int RunProject(XunitProject project, bool teamcity, bool silent, ParallelXunitCommandLine parallelXunitCommandLine)
        {
            if (!parallelXunitCommandLine.Start.HasValue || !parallelXunitCommandLine.End.HasValue)
                return -1;

            int totalAssemblies = 0;
            int totalTests = 0;
            int totalFailures = 0;
            int totalSkips = 0;
            double totalTime = 0;

            var mate = new MultiAssemblyTestEnvironment();

            foreach (XunitProjectAssembly assembly in project.Assemblies)
            {
                parallelXunitCommandLine.SetOutputArguments(assembly.Output);

                TestAssembly testAssembly = mate.Load(assembly.AssemblyFilename, assembly.ConfigFilename, assembly.ShadowCopy);
                List<IResultXmlTransform> transforms = TransformFactory.GetAssemblyTransforms(assembly);

                try
                {
                    var start = parallelXunitCommandLine.Start.Value;
                    var end = parallelXunitCommandLine.End.Value;
                    var methods = new List<TestMethod>(testAssembly.EnumerateTestMethods(project.Filters.Filter)).Skip(start).Take(end - start).ToList();
                    if (methods.Count == 0)
                    {
                        Console.WriteLine("Skipping assembly (no tests match the specified filter).");
                        continue;
                    }

                    var callback = CreateCallback(teamcity, silent, methods.Count);
                    var assemblyXml = testAssembly.Run(methods, callback);

                    ++totalAssemblies;
                    totalTests += callback.TotalTests;
                    totalFailures += callback.TotalFailures;
                    totalSkips += callback.TotalSkips;
                    totalTime += callback.TotalTime;

                    ParallelXunitCommandLine.WriteResultFile(assembly.AssemblyFilename, totalTests, totalFailures, totalSkips, totalTime, start, end);

                    foreach (var transform in transforms)
                        transform.Transform(assemblyXml);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                mate.Unload(testAssembly);
            }

            if (!teamcity && totalAssemblies > 1)
            {
                Console.WriteLine();
                Console.WriteLine("=== {0} total, {1} failed, {2} skipped, took {3} seconds ===",
                                   totalTests, totalFailures, totalSkips, totalTime.ToString("0.000", CultureInfo.InvariantCulture));
            }

            return totalFailures;
        }
Ejemplo n.º 3
0
        static int RunProject(XunitProject project, bool teamcity, bool silent, string[] args)
        {
            var defaultArgs = args.Aggregate((a, b) => a + " " + b);

            var mate = new MultiAssemblyTestEnvironment();
            foreach (XunitProjectAssembly assembly in project.Assemblies)
            {
                TestAssembly testAssembly = mate.Load(assembly.AssemblyFilename, assembly.ConfigFilename, assembly.ShadowCopy);
                var methods = new List<TestMethod>(testAssembly.EnumerateTestMethods(project.Filters.Filter));
                var methodsCount = methods.Count;

                ParallelXunitCommandLine.DeleteResultFiles(assembly.AssemblyFilename);

                using (var waiter = new ProcessWaiter())
                {
                    waiter.DefaultArgs = defaultArgs;
                    waiter.TeamCity = teamcity;
                    waiter.Silent = silent;

                    Console.WriteLine("Running with {0} threads.", waiter.MaximumNumberOfProcesses);
                    Console.WriteLine("Total number of tests: {0}.", methodsCount);

                    IParallelTestMethodRunnerCallback callback = CreateCallback(teamcity, silent, methodsCount);
                    callback.ParentAssemblyStart(testAssembly);

                    TestBatch batch;
                    var batcher = new TestMethodBatcher(methodsCount);
                    while ((batch = batcher.GetNextBatch()).Size > 0)
                    {
                        waiter.StartProcess(batch);
                    }

                    if (!teamcity)
                    {
                        waiter.PrintSummary();
                    }
                    else
                    {
                        waiter.WaitForAllProcesses();
                    }

                    var testResult = ParallelXunitCommandLine.AggregateTestResults(assembly.AssemblyFilename);
                    callback.ParentAssemblyFinished(testAssembly, testResult.Total, testResult.Failed, testResult.Skiped);

                    mate.Unload(testAssembly);
                }
            }

            return 0;
        }
Ejemplo n.º 4
0
        static int RunProject(XunitProject project, bool teamcity, bool silent, string[] args)
        {
            var defaultArgs = args.Aggregate((a, b) => a + " " + b);

            var mate = new MultiAssemblyTestEnvironment();
            foreach (XunitProjectAssembly assembly in project.Assemblies)
            {
                TestAssembly testAssembly = mate.Load(assembly.AssemblyFilename, assembly.ConfigFilename, assembly.ShadowCopy);
                var methods = new List<TestMethod>(testAssembly.EnumerateTestMethods(project.Filters.Filter));

                var batcher = new TestMethodBatcher(methods.Count);

                var waiter = new ProcessWaiter();
                waiter.DefaultArgs = defaultArgs;
                waiter.TeamCity = teamcity;
                waiter.Silent = silent;

                Console.WriteLine("Running with {0} threads.", waiter.MaximumNumberOfProcesses);
                Console.WriteLine("Total number of tests: {0}.", methods.Count);

                TestBatch batch;
                while ((batch = batcher.GetNextBatch()).Size > 0)
                {
                    waiter.StartProcess(batch);
                }

                waiter.PrintSummary();

                mate.Unload(testAssembly);
            }

            return 0;
        }