コード例 #1
0
        public static void AreEqual(Statistics expected, Statistics actual)
        {
            if (expected == null)
            {
                Assert.IsNull(actual);
                return;
            }

            Assert.AreEqual(expected.AssertCount, actual.AssertCount);
            Assert.AreEqual(expected.Duration, actual.Duration);
            Assert.AreEqual(expected.FailedCount, actual.FailedCount);
            Assert.AreEqual(expected.InconclusiveCount, actual.InconclusiveCount);
            Assert.AreEqual(expected.PassedCount, actual.PassedCount);
            Assert.AreEqual(expected.SkippedCount, actual.SkippedCount);
            Assert.AreEqual(expected.RunCount, actual.RunCount);
            Assert.AreEqual(expected.TestCount, actual.TestCount);
        }
コード例 #2
0
 public void TestStart()
 {
     stats = new Statistics();
 }
コード例 #3
0
            private void RenderOutcomeBar(TestOutcome testOutcome, Statistics statistics, bool small)
            {
                writer.Write("<table class=\"outcome-bar\"><tr><td>");
                string status = Enum.GetName(typeof(TestStatus), testOutcome.Status).ToLower();
                writer.Write("<div class=\"outcome-bar status-");
                writer.Write(status);
                if (small)
                    writer.Write(" condensed");
                string title = testOutcome.Category ?? status;
                writer.Write("\" title=\"");
                WriteHtmlEncoded(writer, title);
                writer.Write("\" /></td></tr></table>");

                if (small)
                    return;

                writer.Write("<span class=\"outcome-icons\">");

                writer.Write("<img src=\"");
                WriteHtmlEncoded(writer, formatter.imgUrl.ToString());
                writer.Write("/Passed.gif\" alt=\"Passed\" />");
                writer.Write(statistics.PassedCount);

                writer.Write("<img src=\"");
                WriteHtmlEncoded(writer, formatter.imgUrl.ToString());
                writer.Write("/Failed.gif\" alt=\"Failed\" />");
                writer.Write(statistics.FailedCount);

                writer.Write("<img src=\"");
                WriteHtmlEncoded(writer, formatter.imgUrl.ToString());
                writer.Write("/Ignored.gif\" alt=\"Inconclusive or Skipped\" />");
                writer.Write(statistics.InconclusiveCount + statistics.SkippedCount);

                writer.Write("</span>");
            }
コード例 #4
0
            private static void AddStatistics(Statistics statistics, TestStepRun testStepRun, bool child)
            {
                if (!child)
                {
                    statistics.AssertCount += testStepRun.Result.AssertCount;
                    statistics.Duration += testStepRun.Result.DurationInSeconds;
                }

                if (testStepRun.Step.IsTestCase)
                {
                    switch (testStepRun.Result.Outcome.Status)
                    {
                        case TestStatus.Failed:
                            statistics.FailedCount++;
                            statistics.RunCount++;
                            break;
                        case TestStatus.Inconclusive:
                            statistics.InconclusiveCount++;
                            statistics.RunCount++;
                            break;
                        case TestStatus.Passed:
                            statistics.PassedCount++;
                            statistics.RunCount++;
                            break;
                        case TestStatus.Skipped:
                            statistics.SkippedCount++;
                            break;
                    }
                }

                foreach (TestStepRun childRun in testStepRun.Children)
                    AddStatistics(statistics, childRun, true);
            }
コード例 #5
0
            private void RenderTestStepRun(TestStepRun testStepRun, int nestingLevel, bool flashEnabled, bool recurse)
            {
                formatter.SaveAttachments(testStepRun);

                Statistics statistics = new Statistics();
                AddStatistics(statistics, testStepRun, false);

                writer.Write("<li id=\"testStepRun-");
                WriteHtmlEncoded(writer, testStepRun.Step.Id);
                writer.Write("\">");

                writer.Write("<span class=\"testStepRunHeading testStepRunHeading-Level");
                writer.Write(nestingLevel.ToString(CultureInfo.InvariantCulture));
                writer.Write("\">");

                string testKind = testStepRun.Step.Metadata.GetValue(MetadataKeys.TestKind);
                writer.Write("<span class=\"testKind");
                if (testKind != null)
                {
                    writer.Write(" testKind-");
                    writer.Write(NormalizeTestKindName(testKind));
                }
                writer.Write("\"></span>");

                WriteCodeLocationLink(writer, testStepRun.Step.CodeLocation, () => WriteHtmlEncoded(writer, testStepRun.Step.Name));

                RenderOutcomeBar(testStepRun.Result.Outcome, statistics, (testStepRun.Children.Count == 0));
                writer.Write("</span>");

                // stat panel
                writer.Write("<div id=\"detailPanel-");
                WriteHtmlEncoded(writer, testStepRun.Step.Id);
                writer.Write("\" class=\"panel\">");

                if (nestingLevel == 1)
                {
                    writer.Write("<table class=\"statistics-table\"><tr class=\"alternate-row\">");
                    writer.Write("<td class=\"statistics-label-cell\">Results:</td><td>");
                    writer.Write(FormatStatistics(statistics));
                    writer.Write("</td></tr><tr><td class=\"statistics-label-cell\">Duration:</td><td>");
                    writer.Write(statistics.Duration.ToString("0.000"));
                    writer.Write("s</td></tr><tr class=\"alternate-row\"><td class=\"statistics-label-cell\">Assertions:</td><td>");
                    writer.Write(statistics.AssertCount);
                    writer.Write("</td></tr></table>");
                }
                else
                {
                    writer.Write(String.Format("Duration: {0:0.000}s, Assertions: {1}.", statistics.Duration,
                        statistics.AssertCount));
                }

                // metadata
                RenderMetadata(testStepRun);

                // execution logs
                writer.Write("<div class=\"testStepRun\">");
                //if (testStepRun.TestLog.Streams.Count > 0)
                    RenderExecutionLogStreams(testStepRun, flashEnabled);
                writer.Write("</div>");

                // child steps
                if (recurse)
                {
                    if (testStepRun.Children.Count > 0)
                    {
                        writer.Write("<ul class=\"testStepRunContainer\">");
                        foreach (TestStepRun tsr in testStepRun.Children)
                            RenderTestStepRun(tsr, nestingLevel + 1, flashEnabled, true);
                        writer.Write("</ul>");
                    }
                }
                writer.Write("</div></li>");
            }
コード例 #6
0
 private static string FormatStatistics(Statistics statistics)
 {
     return statistics.FormatTestCaseResultSummary();
 }
コード例 #7
0
 private static string StatusCssClassFromStatistics(Statistics statistics)
 {
     if (statistics.FailedCount > 0)
         return "status-failed";
     if (statistics.InconclusiveCount > 0)
         return "status-inconclusive";
     return statistics.PassedCount > 0 ? "status-passed" : "status-skipped";
 }
コード例 #8
0
            private void RenderNavigator(Statistics statistics, IEnumerable<TestStepRun> rootRuns)
            {
                writer.Write("<div id=\"Navigator\" class=\"navigator\">");
                writer.Write("<a href=\"#Details\" title=\"");
                WriteHtmlEncoded(writer, statistics.FormatTestCaseResultSummary());
                writer.Write("\" class=\"navigator-box ");
                writer.Write(StatusCssClassFromStatistics(statistics));
                writer.Write("\"></a>");
                writer.Write("<div class=\"navigator-stripes\">");

                int count = 0;
                foreach (TestStepRun testStepRun in GetAllRuns(rootRuns))
                    count += 1;

                int i = 0;
                foreach (TestStepRun testStepRun in GetAllRuns(rootRuns))
                {
                    float position = i * 98 / count + 1;
                    i++;

                    if (testStepRun.Result.Outcome.Status == TestStatus.Passed ||
                        (!testStepRun.Step.IsTestCase && testStepRun.Children.Count != 0))
                        continue;

                    writer.Write("<a href=\"#testStepRun-");
                    WriteHtmlEncoded(writer, testStepRun.Step.Id);
                    writer.Write("\" style=\"top: ");
                    writer.Write(position.ToString(CultureInfo.InvariantCulture));
                    writer.Write("%\"");

                    string status = Enum.GetName(typeof(TestStatus), testStepRun.Result.Outcome.Status).ToLower();
                    writer.Write(" class=\"status-");
                    writer.Write(status);
                    writer.Write("\" title=\"");
                    WriteHtmlEncoded(writer, testStepRun.Step.Name);
                    writer.Write(" ");
                    writer.Write(status);
                    writer.Write("\"></a>");
                }

                writer.Write("</div></div>");
            }
コード例 #9
0
            public void RenderReport(IEnumerable<TestStepRun> rootRuns, bool recurse)
            {
                bool flashEnabled = ShouldUseFlash(rootRuns);

                writer.Write("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\r\n");
                writer.Write("<!-- saved from url=(0014)about:internet -->\r\n");

                writer.Write("<html xml:lang=\"en\" lang=\"en\" dir=\"ltr\"><head>");
                writer.Write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
                writer.Write("<title>Gallio Test Report</title>");
                writer.Write("<link rel=\"stylesheet\" type=\"text/css\" href=\"");
                WriteHtmlEncoded(writer, formatter.cssUrl.ToString());
                writer.Write("/Gallio-Report.css\" />");
                writer.Write("<link rel=\"stylesheet\" type=\"text/css\" href=\"");
                WriteHtmlEncoded(writer, formatter.cssUrl.ToString());
                writer.Write("/Gallio-Report.Generated.css\" />");
                writer.Write("<script type=\"text/javascript\"><!--\n");
                writer.Write(File.ReadAllText(Path.Combine(formatter.jsDir, "Gallio-Report.js")));
                if (flashEnabled)
                    writer.Write(File.ReadAllText(Path.Combine(formatter.jsDir, "swfobject.js")));
                writer.Write("\n--></script>");
                writer.Write("</head><body class=\"gallio-report\" style=\"overflow: auto;\">");

                writer.Write("<div id=\"Header\" class=\"header\"><div class=\"header-image\"></div></div>");

                writer.Write("<div id=\"Content\" class=\"content\">");

                Statistics statistics = new Statistics();
                foreach (TestStepRun rootRun in rootRuns)
                    AddStatistics(statistics, rootRun, false);

                RenderNavigator(statistics, rootRuns);

                writer.Write("<div id=\"Details\" class=\"section\"><div class=\"section-content\"><ul class=\"testStepRunContainer\">");

                foreach (TestStepRun testStepRun in rootRuns)
                    RenderTestStepRun(testStepRun, 1, flashEnabled, recurse);

                writer.Write("</ul></div></div></div><script type=\"text/javascript\">reportLoaded();</script></body></html>");
                writer.Flush();
            }
コード例 #10
0
 public void StatisticsSetTest()
 {
     Statistics statistics = new Statistics();
     testPackageRun.Statistics = statistics;
     Assert.AreSame(statistics, testPackageRun.Statistics);
 }
コード例 #11
0
ファイル: Statistics.cs プロジェクト: dougrathbone/mbunit-v3
        /// <summary>
        /// Merges the specified statistics.
        /// </summary>
        /// <param name="other"></param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="other"/> is null.</exception>
        public void MergeWith(Statistics other)
        {
            if (other == null)
                throw new ArgumentNullException("other");

            assertCount += other.AssertCount;
            duration += other.Duration;
            runCount += other.RunCount;
            testCount += other.TestCount;
            stepCount += other.StepCount;
            passedCount += other.PassedCount;
            failedCount += other.FailedCount;
            inconclusiveCount += other.InconclusiveCount;
            skippedCount += other.SkippedCount;

            foreach (var item in other.outcomeCounts)
            {
                if (!outcomeCounts.ContainsKey(item.Key))
                    outcomeCounts.Add(item.Key, 0);

                outcomeCounts[item.Key] += item.Value;
            }
        }