Skip to content

Commit

Permalink
reporters/junit: Use system-out element instead of passed
Browse files Browse the repository at this point in the history
In onsi#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.
  • Loading branch information
dlipovetsky committed Feb 10, 2021
1 parent c75f46e commit 6530676
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
9 changes: 1 addition & 8 deletions reporters/junit_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion reporters/junit_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
})

Expand Down

0 comments on commit 6530676

Please sign in to comment.