コード例 #1
0
ファイル: Program.cs プロジェクト: zabulus/xunit
        static int RunProject(XunitProject project,
                              bool serialize,
                              bool?parallelizeAssemblies,
                              bool?parallelizeTestCollections,
                              int?maxThreadCount,
                              bool diagnosticMessages,
                              bool noColor,
                              bool noAppDomain,
                              bool failSkips)
        {
            XElement assembliesElement = null;
            var      clockTime         = Stopwatch.StartNew();
            var      xmlTransformers   = TransformFactory.GetXmlTransformers(project);
            var      needsXml          = xmlTransformers.Count > 0;
            var      consoleLock       = new object();

            if (!parallelizeAssemblies.HasValue)
            {
                parallelizeAssemblies = project.All(assembly => assembly.Configuration.ParallelizeAssemblyOrDefault);
            }

            if (needsXml)
            {
                assembliesElement = new XElement("assemblies");
            }

            var originalWorkingFolder = Directory.GetCurrentDirectory();

            using (AssemblyHelper.SubscribeResolve())
            {
                if (parallelizeAssemblies.GetValueOrDefault())
                {
                    var tasks   = project.Assemblies.Select(assembly => Task.Run(() => ExecuteAssembly(consoleLock, assembly, serialize, needsXml, parallelizeTestCollections, maxThreadCount, diagnosticMessages, noColor, noAppDomain, failSkips, project.Filters)));
                    var results = Task.WhenAll(tasks).GetAwaiter().GetResult();
                    foreach (var assemblyElement in results.Where(result => result != null))
                    {
                        assembliesElement.Add(assemblyElement);
                    }
                }
                else
                {
                    foreach (var assembly in project.Assemblies)
                    {
                        var assemblyElement = ExecuteAssembly(consoleLock, assembly, serialize, needsXml, parallelizeTestCollections, maxThreadCount, diagnosticMessages, noColor, noAppDomain, failSkips, project.Filters);
                        if (assemblyElement != null)
                        {
                            assembliesElement.Add(assemblyElement);
                        }
                    }
                }

                clockTime.Stop();

                if (completionMessages.Count > 0)
                {
                    reporterMessageHandler.OnMessage(new TestExecutionSummary(clockTime.Elapsed, completionMessages.OrderBy(kvp => kvp.Key).ToList()));
                }
            }

            Directory.SetCurrentDirectory(originalWorkingFolder);

            xmlTransformers.ForEach(transformer => transformer(assembliesElement));

            return(failed ? 1 : completionMessages.Values.Sum(summary => summary.Failed));
        }
コード例 #2
0
        static int RunProject(string defaultDirectory, XunitProject project, bool teamcity, bool appVeyor, bool silent, bool parallelizeAssemblies, bool parallelizeTestCollections, int maxThreadCount)
        {
            XElement assembliesElement = null;
            var      xmlTransformers   = TransformFactory.GetXmlTransformers(project);
            var      needsXml          = xmlTransformers.Count > 0;
            var      consoleLock       = new object();

            if (needsXml)
            {
                assembliesElement = new XElement("assemblies");
            }

            var originalWorkingFolder = Directory.GetCurrentDirectory();

            using (AssemblyHelper.SubscribeResolve())
            {
                if (parallelizeAssemblies)
                {
                    var tasks   = project.Assemblies.Select(assembly => Task.Run(() => ExecuteAssembly(consoleLock, defaultDirectory, assembly, needsXml, teamcity, appVeyor, silent, parallelizeTestCollections, maxThreadCount, project.Filters)));
                    var results = Task.WhenAll(tasks).GetAwaiter().GetResult();
                    foreach (var assemblyElement in results.Where(result => result != null))
                    {
                        assembliesElement.Add(assemblyElement);
                    }
                }
                else
                {
                    foreach (var assembly in project.Assemblies)
                    {
                        var assemblyElement = ExecuteAssembly(consoleLock, defaultDirectory, assembly, needsXml, teamcity, appVeyor, silent, parallelizeTestCollections, maxThreadCount, project.Filters);
                        if (assemblyElement != null)
                        {
                            assembliesElement.Add(assemblyElement);
                        }
                    }
                }

                if (completionMessages.Count > 0)
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine();
                    Console.WriteLine("=== TEST EXECUTION SUMMARY ===");
                    Console.ForegroundColor = ConsoleColor.Gray;

                    var totalTestsRun       = completionMessages.Values.Sum(summary => summary.Total);
                    var totalTestsFailed    = completionMessages.Values.Sum(summary => summary.Failed);
                    var totalTestsSkipped   = completionMessages.Values.Sum(summary => summary.Skipped);
                    var totalTime           = completionMessages.Values.Sum(summary => summary.Time).ToString("0.000s");
                    var totalErrors         = completionMessages.Values.Sum(summary => summary.Errors);
                    var longestAssemblyName = completionMessages.Keys.Max(key => key.Length);
                    var longestTotal        = totalTestsRun.ToString().Length;
                    var longestFailed       = totalTestsFailed.ToString().Length;
                    var longestSkipped      = totalTestsSkipped.ToString().Length;
                    var longestTime         = totalTime.Length;
                    var longestErrors       = totalErrors.ToString().Length;

                    foreach (var message in completionMessages.OrderBy(m => m.Key))
                    {
                        Console.WriteLine("   {0}  Total: {1}, Failed: {2}, Skipped: {3}, Time: {4}, Errors: {5}",
                                          message.Key.PadRight(longestAssemblyName),
                                          message.Value.Total.ToString().PadLeft(longestTotal),
                                          message.Value.Failed.ToString().PadLeft(longestFailed),
                                          message.Value.Skipped.ToString().PadLeft(longestSkipped),
                                          message.Value.Time.ToString("0.000s").PadLeft(longestTime),
                                          message.Value.Errors.ToString().PadLeft(longestErrors));
                    }

                    if (completionMessages.Count > 1)
                    {
                        Console.WriteLine("   {0}         {1}          {2}           {3}        {4}          {5}" + Environment.NewLine +
                                          "           {6} {7}          {8}           {9}        {10}          {11}",
                                          " ".PadRight(longestAssemblyName),
                                          "-".PadRight(longestTotal, '-'),
                                          "-".PadRight(longestFailed, '-'),
                                          "-".PadRight(longestSkipped, '-'),
                                          "-".PadRight(longestTime, '-'),
                                          "-".PadRight(longestErrors, '-'),
                                          "GRAND TOTAL:".PadLeft(longestAssemblyName),
                                          totalTestsRun,
                                          totalTestsFailed,
                                          totalTestsSkipped,
                                          totalTime,
                                          totalErrors);
                    }
                }
            }

            Directory.SetCurrentDirectory(originalWorkingFolder);

            xmlTransformers.ForEach(transformer => transformer(assembliesElement));

            return(failed ? 1 : completionMessages.Values.Sum(summary => summary.Failed));
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: paynetechnologies/xunit
        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);
        }
コード例 #4
0
        int RunProject(XunitProject project,
                       bool serialize,
                       bool?parallelizeAssemblies,
                       bool?parallelizeTestCollections,
                       int?maxThreadCount,
                       bool diagnosticMessages,
                       bool noColor,
                       AppDomainSupport?appDomains,
                       bool failSkips,
                       bool stopOnFail,
                       bool internalDiagnosticMessages)
        {
            XElement assembliesElement = null;
            var      clockTime         = Stopwatch.StartNew();
            var      xmlTransformers   = TransformFactory.GetXmlTransformers(project);
            var      needsXml          = xmlTransformers.Count > 0;

            if (!parallelizeAssemblies.HasValue)
            {
                parallelizeAssemblies = project.All(assembly => assembly.Configuration.ParallelizeAssemblyOrDefault);
            }

            logger.LogMessage($"NeedsXml: {needsXml}");
            if (needsXml)
            {
                assembliesElement = new XElement("assemblies");
            }

            var originalWorkingFolder = Directory.GetCurrentDirectory();

            if (parallelizeAssemblies.GetValueOrDefault())
            {
                var tasks   = project.Assemblies.Select(assembly => Task.Run(() => ExecuteAssembly(consoleLock, assembly, serialize, needsXml, parallelizeTestCollections, maxThreadCount, diagnosticMessages, noColor, appDomains, failSkips, stopOnFail, project.Filters, internalDiagnosticMessages)));
                var results = Task.WhenAll(tasks).GetAwaiter().GetResult();
                foreach (var assemblyElement in results.Where(result => result != null))
                {
                    logger.LogMessage($"AssembliesElement: {assembliesElement?.ToString()}");
                    assembliesElement.Add(assemblyElement);
                }
            }
            else
            {
                foreach (var assembly in project.Assemblies)
                {
                    var assemblyElement = ExecuteAssembly(consoleLock, assembly, serialize, needsXml, parallelizeTestCollections, maxThreadCount, diagnosticMessages, noColor, appDomains, failSkips, stopOnFail, project.Filters, internalDiagnosticMessages);
                    if (assemblyElement != null)
                    {
                        logger.LogMessage($"AssembliesElement before add assembly {assembly.AssemblyFilename}: {assembliesElement?.ToString()}");
                        assembliesElement.Add(assemblyElement);
                    }
                }
            }

            clockTime.Stop();

            logger.LogMessage($"AssembliesElement before adding timestamp: {assembliesElement?.ToString()}");

            if (assembliesElement != null)
            {
                assembliesElement.Add(new XAttribute("timestamp", DateTime.Now.ToString(CultureInfo.InvariantCulture)));
            }

            if (completionMessages.Count > 0)
            {
                reporterMessageHandler.OnMessage(new TestExecutionSummary(clockTime.Elapsed, completionMessages.OrderBy(kvp => kvp.Key).ToList()));
            }

            Directory.SetCurrentDirectory(originalWorkingFolder);

            xmlTransformers.ForEach(transformer => transformer(assembliesElement));

            return(failed ? 1 : completionMessages.Values.Sum(summary => summary.Failed));
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: ravendb/xunit
        static int RunProject(string defaultDirectory, XunitProject project, bool teamcity, bool silent, bool parallel)
        {
            XElement assembliesElement = null;
            var      xmlTransformers   = TransformFactory.GetXmlTransformers(project);
            var      needsXml          = xmlTransformers.Count > 0;
            var      consoleLock       = new object();

            if (needsXml)
            {
                assembliesElement = new XElement("assemblies");
            }

            string originalWorkingFolder = Directory.GetCurrentDirectory();

            using (AssemblyHelper.SubscribeResolve())
            {
                if (parallel)
                {
                    var tasks   = project.Assemblies.Select(assembly => Task.Run(() => ExecuteAssembly(consoleLock, defaultDirectory, assembly, needsXml, teamcity, silent)));
                    var results = Task.WhenAll(tasks).GetAwaiter().GetResult();
                    foreach (var assemblyElement in results.Where(result => result != null))
                    {
                        assembliesElement.Add(assemblyElement);
                    }
                }
                else
                {
                    foreach (var assembly in project.Assemblies)
                    {
                        var assemblyElement = ExecuteAssembly(consoleLock, defaultDirectory, assembly, needsXml, teamcity, silent);
                        if (assemblyElement != null)
                        {
                            assembliesElement.Add(assemblyElement);
                        }
                    }
                }

                if (completionMessages.Count > 0)
                {
                    Console.WriteLine();
                    Console.WriteLine("=== TEST EXECUTION SUMMARY ===");
                    int longestAssemblyName = completionMessages.Keys.Max(key => key.Length);
                    int longestTotal        = completionMessages.Values.Max(summary => summary.Total.ToString().Length);
                    int longestFailed       = completionMessages.Values.Max(summary => summary.Failed.ToString().Length);
                    int longestSkipped      = completionMessages.Values.Max(summary => summary.Skipped.ToString().Length);
                    int longestTime         = completionMessages.Values.Max(summary => summary.Time.ToString("0.000s").Length);

                    foreach (var message in completionMessages.OrderBy(m => m.Key))
                    {
                        Console.WriteLine("   {0}  Total: {1}, Failed: {2}, Skipped: {3}, Time: {4}",
                                          message.Key.PadRight(longestAssemblyName),
                                          message.Value.Total.ToString().PadLeft(longestTotal),
                                          message.Value.Failed.ToString().PadLeft(longestFailed),
                                          message.Value.Skipped.ToString().PadLeft(longestSkipped),
                                          message.Value.Time.ToString("0.000s").PadLeft(longestTime));
                    }
                }
            }

            Directory.SetCurrentDirectory(originalWorkingFolder);

            xmlTransformers.ForEach(transformer => transformer(assembliesElement));

            return(completionMessages.Values.Sum(summary => summary.Failed));
        }