gotestsum icon indicating copy to clipboard operation
gotestsum copied to clipboard

Include test output for successful tests in junitfile

Open arthurvaverko-kaltura opened this issue 5 years ago • 9 comments

My tests print out logs using t.Log(..) is there any way to display these logs inside a junit output ?

arthurvaverko-kaltura avatar May 17 '20 19:05 arthurvaverko-kaltura

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?

dnephin avatar May 17 '20 20:05 dnephin

Looking for all output .. If you can point me to the correct location I could do a pull request ..

arthurvaverko-kaltura avatar May 17 '20 20:05 arthurvaverko-kaltura

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?

dnephin avatar May 17 '20 21:05 dnephin

I don't but I'll try to look into it soon ...

arthurvaverko-kaltura avatar May 18 '20 05:05 arthurvaverko-kaltura

@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.

sodul avatar Jul 02 '20 02:07 sodul

I opened a Pr for this https://github.com/gotestyourself/gotestsum/pull/327

alexxed avatar Apr 25 '23 11:04 alexxed

#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.

dnephin avatar Nov 04 '23 17:11 dnephin

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>

rkeithhill-keysight avatar Nov 09 '23 00:11 rkeithhill-keysight