示例#1
0
        static int RunProject(XunitProject project, bool teamcity, bool silent)
        {
            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)
            {
                TestAssembly testAssembly             = mate.Load(assembly.AssemblyFilename, assembly.ConfigFilename, assembly.ShadowCopy);
                List <IResultXmlTransform> transforms = TransformFactory.GetAssemblyTransforms(assembly);

                Console.WriteLine();
                Console.WriteLine("xunit.dll:     Version {0}", testAssembly.XunitVersion);
                Console.WriteLine("Test assembly: {0}", testAssembly.AssemblyFilename);
                Console.WriteLine();

                try
                {
                    var methods = new List <TestMethod>(testAssembly.EnumerateTestMethods(project.Filters.Filter));
                    if (methods.Count == 0)
                    {
                        Console.WriteLine("Skipping assembly (no tests match the specified filter).");
                        continue;
                    }

                    var callback =
                        teamcity ? (RunnerCallback) new TeamCityRunnerCallback()
                                 : new StandardRunnerCallback(silent, methods.Count);
                    var assemblyXml = testAssembly.Run(methods, callback);

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

                    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);
        }