Beispiel #1
0
        static ExecutionResult Execute(CommandLineParser commandLineParser)
        {
            var options = commandLineParser.Options;

            var summary = new ExecutionResult();

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            foreach (var assemblyPath in commandLineParser.AssemblyPaths)
            {
                var result = Execute(assemblyPath, options);

                summary.Add(result);
            }

            stopwatch.Stop();

            if (summary.AssemblyResults.Count > 1)
                Summarize(summary, stopwatch.Elapsed);

            SaveReport(options, summary);

            return summary;
        }
Beispiel #2
0
        static int Main(string[] args)
        {
            try
            {
                var commandLineParser = new CommandLineParser(args);

                if (commandLineParser.HasErrors)
                {
                    using (Foreground.Red)
                        foreach (var error in commandLineParser.Errors)
                            Console.WriteLine(error);

                    Console.WriteLine();
                    Console.WriteLine(CommandLineParser.Usage());
                    return FatalError;
                }

                foreach (var assemblyPath in commandLineParser.AssemblyPaths)
                {
                    if (!File.Exists(assemblyPath))
                    {
                        using (Foreground.Red)
                            Console.WriteLine("Specified test assembly does not exist: " + assemblyPath);

                        Console.WriteLine();
                        Console.WriteLine(CommandLineParser.Usage());
                        return FatalError;
                    }
                }

                var executionResult = new ExecutionResult();

                var stopwatch = new Stopwatch();
                stopwatch.Start();

                foreach (var assemblyPath in commandLineParser.AssemblyPaths)
                {
                    var result = Execute(assemblyPath, commandLineParser.Options);

                    executionResult.Add(result);
                }

                stopwatch.Stop();

                if (executionResult.AssemblyResults.Count > 1)
                    Summarize(executionResult, stopwatch.Elapsed);

                ProduceReports(commandLineParser.Options, executionResult);

                return executionResult.Failed;
            }
            catch (Exception exception)
            {
                using (Foreground.Red)
                    Console.WriteLine("Fatal Error: {0}", exception);
                return FatalError;
            }
        }
Beispiel #3
0
        public XDocument Transform(ExecutionResult executionResult)
        {
            var now = DateTime.UtcNow;

            return new XDocument(
                new XElement("test-results",
                    new XAttribute("date", now.ToString("yyyy-MM-dd")),
                    new XAttribute("time", now.ToString("HH:mm:ss")),
                    new XAttribute("name", "Results"),
                    new XAttribute("total", executionResult.Total),
                    new XAttribute("failures", executionResult.Failed),
                    new XAttribute("not-run", executionResult.Skipped),
                    executionResult.AssemblyResults.Select(Assembly)));
        }
Beispiel #4
0
        static ExecutionResult Execute(CommandLineParser commandLineParser)
        {
            var options = commandLineParser.Options;

            var summary = new ExecutionResult();

            foreach (var assemblyPath in commandLineParser.AssemblyPaths)
            {
                var result = Execute(assemblyPath, options);

                summary.Add(result);
            }

            SaveReport(options, summary);

            return summary;
        }
Beispiel #5
0
        public void ShouldProduceValidXmlDocument()
        {
            var listener = new StubListener();
            var runner = new Runner(listener);

            var executionResult = new ExecutionResult();
            var convention = SelfTestConvention.Build();
            convention.CaseExecution.Skip(x => x.Method.Has<SkipAttribute>(), x => x.Method.GetCustomAttribute<SkipAttribute>().Reason);
            convention.Parameters.Add<InputAttributeParameterSource>();
            var assemblyResult = runner.RunTypes(GetType().Assembly, convention, typeof(PassFailTestClass));
            executionResult.Add(assemblyResult);

            var report = new XUnitXmlReport();
            var actual = report.Transform(executionResult);

            XsdValidate(actual);
            CleanBrittleValues(actual.ToString(SaveOptions.DisableFormatting)).ShouldEqual(ExpectedReport);
        }
      private static void RunTests(IReadOnlyCollection<string> testAssemblyPaths, string uri)
      {
         try
         {
            var executionResult = new ExecutionResult();

            foreach (var assemblyPath in testAssemblyPaths)
            {
               var listener = CreateListener(uri);
               using (var environment = new ExecutionEnvironment(assemblyPath))
                  executionResult.Add(environment.RunAssembly(new Options(), listener));
            }
         }
         catch (Exception exception)
         {
            Debug.Fail(exception.ToString());
         }
      }
Beispiel #7
0
        static void SaveReport(Options options, ExecutionResult executionResult)
        {
            if (options.Contains(CommandLineOption.NUnitXml))
            {
                var xDocument = new NUnitXmlReport().Transform(executionResult);

                foreach (var fileName in options[CommandLineOption.NUnitXml])
                    xDocument.Save(fileName, SaveOptions.None);
            }

            if (options.Contains(CommandLineOption.XUnitXml))
            {
                var xDocument = new XUnitXmlReport().Transform(executionResult);

                foreach (var fileName in options[CommandLineOption.XUnitXml])
                    xDocument.Save(fileName, SaveOptions.None);
            }
        }
Beispiel #8
0
        public XDocument Transform(ExecutionResult executionResult)
        {
            var now = DateTime.UtcNow;

            return new XDocument(
                new XElement("test-results",
                    new XAttribute("date", now.ToString("yyyy-MM-dd")),
                    new XAttribute("time", now.ToString("HH:mm:ss")),
                    new XAttribute("name", "Results"),
                    new XAttribute("total", executionResult.Total),
                    new XAttribute("failures", executionResult.Failed),
                    new XAttribute("not-run", executionResult.Skipped),

                    //Fixie has fewer test states than NUnit, so these counts are always zero.
                    new XAttribute("errors", 0), //Already accounted for by "failures" above.
                    new XAttribute("inconclusive", 0), //No such status.
                    new XAttribute("ignored", 0), //Already accounted for by "not-run" above.
                    new XAttribute("skipped", 0), //Already accounted for by "not-run" above.
                    new XAttribute("invalid", 0), //Already accounted for by "failures" above.

                    Environment(),
                    CultureInfo(),
                    executionResult.AssemblyResults.Select(Assembly)));
        }
Beispiel #9
0
        static void Summarize(ExecutionResult executionResult, TimeSpan elapsed)
        {
            var line = new StringBuilder();

            line.AppendFormat("{0} passed", executionResult.Passed);
            line.AppendFormat(", {0} failed", executionResult.Failed);

            if (executionResult.Skipped > 0)
                line.AppendFormat(", {0} skipped", executionResult.Skipped);

            line.AppendFormat(", took {0:N2} seconds", elapsed.TotalSeconds);

            Console.WriteLine("====== " + line + " ======");
        }
Beispiel #10
0
 public XDocument Transform(ExecutionResult executionResult)
 {
     return new XDocument(
         new XElement("assemblies",
             executionResult.AssemblyResults.Select(Assembly)));
 }