如何在junit 5 gradle测试报告中捕获stdout / stderr? [英] How to capture stdout/stderr in junit 5 gradle test report?

查看:306
本文介绍了如何在junit 5 gradle测试报告中捕获stdout / stderr?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的gradle项目使用junit 5,我试图让测试报告显示在我的构建服务器上。 XML报告基本上看起来很好 - 它包含了所有的测试类和方法,但缺少在测试方法中打印的stdout / stderr。只有一些包含CDATA的测试元数据。

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

XML报表:

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

是否有设置告诉gradle插件捕获stdout / stderr?我环顾了 http://junit.org/junit5/ docs / current / user-guide /#running-tests-build 但找不到任何文件。



我正在使用 org .junit.platform:junit-platform-gradle-plugin:1.0.0-M3 org.junit.jupiter:junit-jupiter- {api,engine}:5.0。 0-M3

解决方案

正如Marc Philipp所说,目前还不支持捕获输出到如果你想要这样一个功能,请在这里提出一个问题: https://github.com/junit-team/junit5/issues



更新(2017.11.01)

通知:作为概念验证,我移植了基于<$从Spring Boot到JUnit Jupiter的c $ c> OutputCapture 规则在这里: https://github.com/ sbrannen / junit5-demo / blob / master / src / test / java / extensions / CaptureSystemOutput.java


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.

解决方案

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

这篇关于如何在junit 5 gradle测试报告中捕获stdout / stderr?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆