How to capture stdout/stderr in junit 5 gradle test report?

六眼飞鱼酱① 提交于 2020-01-24 06:43:33

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/43151448/how-to-capture-stdout-stderr-in-junit-5-gradle-test-report

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!