Exemplo n.º 1
0
        int RunProject(XunitProject project,
                       bool?parallelizeTestCollections,
                       int?maxThreadCount,
                       bool diagnosticMessages,
                       bool noColor,
                       bool failSkips,
                       bool stopOnFail,
                       bool internalDiagnosticMessages)
        {
            XElement assembliesElement = null;
            var      clockTime         = Stopwatch.StartNew();
            var      xmlTransformers   = TransformFactory.GetXmlTransformers(project);
            var      needsXml          = xmlTransformers.Count > 0;

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

            var originalWorkingFolder = Directory.GetCurrentDirectory();

            var assembly        = project.Assemblies.Single();
            var assemblyElement = ExecuteAssembly(consoleLock, assembly, needsXml, parallelizeTestCollections, maxThreadCount, diagnosticMessages, noColor, failSkips, stopOnFail, project.Filters, internalDiagnosticMessages);

            if (assemblyElement != null)
            {
                assembliesElement.Add(assemblyElement);
            }

            clockTime.Stop();

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

            var summary   = new KeyValuePair <string, ExecutionSummary>(Path.GetFileNameWithoutExtension(assembly.AssemblyFilename), executionSummary);
            var summaries = new List <KeyValuePair <string, ExecutionSummary> > {
                summary
            };

            reporterMessageHandler.OnMessage(new TestExecutionSummary(clockTime.Elapsed, summaries));

            Directory.SetCurrentDirectory(originalWorkingFolder);

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

            return(failed ? 1 : executionSummary.Failed);
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 5
0
        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));
        }