Exemplo n.º 1
0
        /// <summary>
        /// Prints the Summary Report
        /// </summary>
        public void DisplaySummaryReport(ResultSummary summary)
        {
            var status = summary.ResultState.Status;

            var overallResult = status.ToString();

            if (overallResult == "Skipped")
            {
                overallResult = "Warning";
            }

            ColorStyle overallStyle = status == TestStatus.Passed
                ? ColorStyle.Pass
                : status == TestStatus.Failed
                    ? ColorStyle.Failure
                    : status == TestStatus.Skipped
                        ? ColorStyle.Warning
                        : ColorStyle.Output;

            // if (_testCreatedOutput)
            //     Writer.WriteLine();

            WriteSectionHeader("Test Run Summary");
            WriteLabelLine("  Overall result: ", overallResult, overallStyle);

            WriteSummaryCount("  Test Count: ", summary.TestCount);
            WriteSummaryCount(", Passed: ", summary.PassCount);
            WriteSummaryCount(", Failed: ", summary.FailedCount, ColorStyle.Failure);
            WriteSummaryCount(", Warnings: ", summary.WarningCount, ColorStyle.Warning);
            WriteSummaryCount(", Inconclusive: ", summary.InconclusiveCount);
            //WriteSummaryCount(", Skipped: ", summary.TotalSkipCount);
            _writer.WriteLine();

            if (summary.FailedCount > 0)
            {
                WriteSummaryCount("    Failed Tests - Failures: ", summary.FailureCount, ColorStyle.Failure);
                WriteSummaryCount(", Errors: ", summary.ErrorCount, ColorStyle.Error);
                WriteSummaryCount(", Invalid: ", summary.InvalidCount, ColorStyle.Error);
                _writer.WriteLine();
            }

            if (summary.NotRunCount > 0)
            {
                WriteSummaryCount("    Skipped Tests - Ignored: ", summary.IgnoreCount, ColorStyle.Warning);
                //WriteSummaryCount(", Explicit: ", summary.ExplicitCount);
                WriteSummaryCount(", Other: ", summary.SkipCount);
                _writer.WriteLine();
            }

            //writer.WriteLabelLine("  Start time: ", summary.StartTime.ToString("u"));
            //writer.WriteLabelLine("    End time: ", summary.EndTime.ToString("u"));
            WriteLabelLine("    Duration: ", string.Format(NumberFormatInfo.InvariantInfo, "{0:0.000} seconds", summary.Duration));
            _writer.WriteLine();
        }
Exemplo n.º 2
0
        private void InitializeXmlFile(ITestResult result)
        {
            ResultSummary summaryResults = new ResultSummary(result);

            xmlWriter.WriteStartDocument(false);
            xmlWriter.WriteComment("This file represents the results of running a test suite");

            xmlWriter.WriteStartElement("test-results");

            xmlWriter.WriteAttributeString("name", result.FullName);
            xmlWriter.WriteAttributeString("total", summaryResults.TestCount.ToString());
            xmlWriter.WriteAttributeString("errors", summaryResults.ErrorCount.ToString());
            xmlWriter.WriteAttributeString("failures", summaryResults.FailureCount.ToString());
            xmlWriter.WriteAttributeString("not-run", summaryResults.NotRunCount.ToString());
            xmlWriter.WriteAttributeString("inconclusive", summaryResults.InconclusiveCount.ToString());
            xmlWriter.WriteAttributeString("ignored", summaryResults.IgnoreCount.ToString());
            xmlWriter.WriteAttributeString("skipped", summaryResults.SkipCount.ToString());
            xmlWriter.WriteAttributeString("invalid", summaryResults.InvalidCount.ToString());

            xmlWriter.WriteAttributeString("date", XmlConvert.ToString(startTime, "yyyy-MM-dd"));
            xmlWriter.WriteAttributeString("time", XmlConvert.ToString(startTime, "HH:mm:ss"));
            WriteEnvironment();
            WriteCultureInfo();
        }
Exemplo n.º 3
0
        private int RunTests(ITestFilter filter)
        {
            var labelsOption = _options.DisplayTestLabels?.ToUpper(System.Globalization.CultureInfo.InvariantCulture);

            if (!string.IsNullOrEmpty(labelsOption))
            {
                _displayBeforeTest   = labelsOption == "BEFORE";
                _displayAfterTest    = labelsOption == "AFTER";
                _displayBeforeOutput = _displayBeforeTest || _displayAfterTest || labelsOption == "ON";

                if (_displayBeforeOutput)
                {
                    Console.SetOut(new TextCapture(this, TestOutputType.Out));
                    Console.SetError(new TextCapture(this, TestOutputType.Error));
                }
            }

            DateTime startTime = DateTime.Now;

            ITestResult result = _runner.Run(this, filter);

            var summary = new ResultSummary(result);

            if (summary.FailureCount > 0 || summary.ErrorCount > 0 || summary.WarningCount > 0)
            {
                _textUI.DisplayErrorsFailuresAndWarningsReport(result);
            }

            if (summary.NotRunCount > 0)
            {
                _textUI.DisplayNotRunReport(result);
            }

            //if (commandLineOptions.Full)
            //    PrintFullReport(result);

            _textUI.DisplaySummaryReport(summary);

            if (!_options.NoResult)
            {
                string resultFile = _options.ResultFile ?? "TestResult.xml";
                if (!Path.IsPathRooted(resultFile))
                {
                    resultFile = Path.Combine(_workDirectory, resultFile);
                }
                string resultFormat = _options.ResultFormat ?? "nunit3";

                if (resultFormat == "nunit3")
                {
                    new NUnit3XmlOutputWriter(startTime).WriteResultFile(result, resultFile);
                }
                else if (resultFormat == "nunit2")
                {
                    new NUnit2XmlOutputWriter(startTime).WriteResultFile(result, resultFile);
                }
                else
                {
                    throw new InvalidOperationException($"Invalid result format: {resultFormat}");
                }

                _textUI.DisplaySavedResultMessage(resultFile, resultFormat);
            }

            return(Math.Min(100, summary.FailedCount));
        }