Include test output for successful tests in junitfile
My tests print out logs using t.Log(..)
is there any way to display these logs inside a junit output ?
Thank you for your interest in gotestsum! The log output for failed and skipped tests is included in the report (source), but gotestsum drops the output of tests once the test passes, so it is not available to the report. The rational is that some tests suites may produce a lot of output, and I didn't want to store all of it in memory.
It is possible that a new flag could be added to preserve all of the output, including that of passed tests.
Are you looking for only the failure output, or output for passed tests as well?
Looking for all output .. If you can point me to the correct location I could do a pull request ..
https://github.com/gotestyourself/gotestsum/blob/master/testjson/execution.go#L275-L276 is the line, but I think there may still be other parts of the code that assume this output is removed. If I remember correctly PrintSummary in testjson/summary.go may need to be changed.
https://github.com/gotestyourself/gotestsum/blob/6cbcac1/internal/junitxml/report.go#L173-L176 will also need to be changed to include the output in the report. There is no field for that right now on the struct. Do you know what the xml tag name should be?
I don't but I'll try to look into it soon ...
@arthurvaverko you could use the --jsonfile output to preserve all the output, if you just need it for reference just in case.
Adding a flag to preserve the output for all test could be nice, but we really prefer the current behavior.
I opened a Pr for this https://github.com/gotestyourself/gotestsum/pull/327
#380 was opened recently and sounds like the same ask. I think maybe we should close one of these issues as a duplicate. The discussion in that issue made me realize it's not clear where system-out is supposed to go.
It sounds like #327 and others in these issues are expecting it as a child tag ex:
<testcase>
<system-out></system-out>
</testcase>
If I look at all the top hits on google (https://github.com/windyroad/JUnit-Schema/blob/master/JUnit.xsd, https://github.com/testmoapp/junitxml, https://stackoverflow.com/a/9410271/444646) they put system-out as a sibling to testcase (not a child), so the output would be associated with the testsuite, not the testcase.
Does anyone have an example of the schema that puts system-out under test-case ?
Edit: Ah https://github.com/testmoapp/junitxml does actually show it as both. So I guess that's where it comes from.
Ah, <system-out> is what go-junit-report uses to capture stdout for passed tests:
<testcase name="TestIsAliveSuite" classname="internal/foo" time="0.000">
<system-out><![CDATA[ suite.go:229: warning: no tests to run]]></system-out>
</testcase>