From 6530676eacb89a9a9c9ae8f021771b2ed6aec034 Mon Sep 17 00:00:00 2001 From: Daniel Lipovetsky Date: Tue, 9 Feb 2021 17:29:05 -0800 Subject: [PATCH] reporters/junit: Use `system-out` element instead of `passed` In #586, the JUnit reporter was extended to capture the output of passing tests when the -reportPassing flag is used. However, the passed element is not in the JUnit XML schema. While that alone might a theoretical problem, it is also a practical problem, because some parsers, e.g., the TeamCity XML Reporting Plugin JUnit parser, conform to that schema, ignore the element, and show no output for passing tests. The fix seems to be to use the system-out element instead. I have confirmed that, when using the system-out attribute, the TeamCity XML Reporting Plugin Junit parser shows output for a passing test. --- reporters/junit_reporter.go | 9 +-------- reporters/junit_reporter_test.go | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/reporters/junit_reporter.go b/reporters/junit_reporter.go index 963caaaff..01ddca6e1 100644 --- a/reporters/junit_reporter.go +++ b/reporters/junit_reporter.go @@ -33,17 +33,12 @@ type JUnitTestSuite struct { type JUnitTestCase struct { Name string `xml:"name,attr"` ClassName string `xml:"classname,attr"` - PassedMessage *JUnitPassedMessage `xml:"passed,omitempty"` FailureMessage *JUnitFailureMessage `xml:"failure,omitempty"` Skipped *JUnitSkipped `xml:"skipped,omitempty"` Time float64 `xml:"time,attr"` SystemOut string `xml:"system-out,omitempty"` } -type JUnitPassedMessage struct { - Message string `xml:",chardata"` -} - type JUnitFailureMessage struct { Type string `xml:"type,attr"` Message string `xml:",chardata"` @@ -114,9 +109,7 @@ func (reporter *JUnitReporter) SpecDidComplete(specSummary *types.SpecSummary) { ClassName: reporter.testSuiteName, } if reporter.ReporterConfig.ReportPassed && specSummary.State == types.SpecStatePassed { - testCase.PassedMessage = &JUnitPassedMessage{ - Message: specSummary.CapturedOutput, - } + testCase.SystemOut = specSummary.CapturedOutput } if specSummary.State == types.SpecStateFailed || specSummary.State == types.SpecStateTimedOut || specSummary.State == types.SpecStatePanicked { testCase.FailureMessage = &JUnitFailureMessage{ diff --git a/reporters/junit_reporter_test.go b/reporters/junit_reporter_test.go index e0bc11549..8b07fedaf 100644 --- a/reporters/junit_reporter_test.go +++ b/reporters/junit_reporter_test.go @@ -93,7 +93,7 @@ var _ = Describe("JUnit Reporter", func() { Expect(output.TestCases[0].FailureMessage).To(BeNil()) Expect(output.TestCases[0].Skipped).To(BeNil()) Expect(output.TestCases[0].Time).To(Equal(5.0)) - Expect(output.TestCases[0].PassedMessage.Message).To(ContainSubstring("Test scenario")) + Expect(output.TestCases[0].SystemOut).To(ContainSubstring("Test scenario")) }) })