6

My gradle project uses junit 5 and I'm trying to get the test reports to show up on my build server. The XML report basically looks fine – it contains all the test classes and methods, but it is missing stdout/stderr printed in test methods. There is only some CDATA containing test metadata.

@Test
void testToString() {
    System.out.println("Hello world");
    ...
}

XML report:

<testcase name="testToString()" classname="com.my.company.PairsTest" time="0.008">
<system-out><![CDATA[
unique-id: [engine:junit-jupiter]/[class:com.my.company.PairsTest]/[method:testToString()]
display-name: testToString()
]]></system-out>
</testcase>

Is there a setting to tell the gradle plugin to capture stdout/stderr? I looked around http://junit.org/junit5/docs/current/user-guide/#running-tests-build but couldn't find any.

I am using org.junit.platform:junit-platform-gradle-plugin:1.0.0-M3 and org.junit.jupiter:junit-jupiter-{api,engine}:5.0.0-M3.

mkobit
  • 43,979
  • 12
  • 156
  • 150
Max Ng
  • 449
  • 1
  • 4
  • 10
  • Output to stdout/stderr is currently not captured. Can you switch to using TestReporter instead? https://github.com/junit-team/junit5/blob/master/documentation/src/test/java/example/TestReporterDemo.java – Marc Philipp Apr 02 '17 at 07:58
  • Most of the stdout/stderr are generated by the code being tested so they won't be able to use TestReporter. – Max Ng Apr 03 '17 at 17:41
  • (hit return too soon) @MarcPhilipp will there be plans to support capturing stdout/stderr in junit, or should I file a feature suggestion or PR somewhere? IMO the output is quite useful for understanding test failures on CI servers, esp. if the failures are not reproducible locally. – Max Ng Apr 03 '17 at 17:45

1 Answers1

5

As Marc Philipp mentioned, there is currently no support for capturing output to STDERR or STDOUT in JUnit 5, neither in the Platform nor in Jupiter.

If you would like such a feature, please raise an issue here: https://github.com/junit-team/junit5/issues

Update (2017.11.01)

FYI: as a proof of concept, I ported the JUnit 4 based OutputCapture rule from Spring Boot to JUnit Jupiter here: https://github.com/sbrannen/junit5-demo/blob/master/src/test/java/extensions/CaptureSystemOutput.java

Sam Brannen
  • 29,611
  • 5
  • 104
  • 136