Gradle:如何将测试 STDERR/STDOUT 的输出输出到控制台? [英] Gradle: How to get output from test STDERR/STDOUT into console?

查看:40
本文介绍了Gradle:如何将测试 STDERR/STDOUT 的输出输出到控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(Gradle 3.2.1) 我运行了一些 java 测试,将输出记录在 Stderr/Stdout 中.我可以看到输出,如果我开始

(Gradle 3.2.1) I run some java tests, which logs output in Stderr/Stdout. I can see that output, if I start

gradle test --info

但在这种情况下,来自第 3 方库的许多不需要的输出也存在.

but in that case, much of unwanted output from 3-rd party libraries is there too.

文档 建议使用 logging.caputureStandardError/logging.caputureStandardError(loglevel),但是好像没有什么作用.

Documentation suggests using logging.caputureStandardError / logging.caputureStandardError (loglevel), but it doesn't seem to have any effect.

tasks.withType(Test) {
   logging.captureStandardOutput LogLevel.QUIET
   logging.captureStandardError LogLevel.QUIET
}

然后如果运行gradle test,控制台输出的不是STDERR/STDOUT.

Then if running gradle test, not STDERR/STDOUT is output in console.

如何在控制台中只获取测试类的输出?

How can I get just the output from the tests classes in console?

推荐答案

将这些行添加到 build.gradle :

apply plugin: 'java'

test {
    dependsOn cleanTest
    testLogging.showStandardStreams = true
}

注意:dependsOn cleanTest 不是必须的,但是如果没有使用,你需要运行 cleanTest 或 <test 任务之前的 code>clean 任务.

Notice: dependsOn cleanTest is not necessary but if not used, you need to run cleanTest or clean task before test task.

更好的方法:

apply plugin: 'java'

test {
    testLogging {
        outputs.upToDateWhen {false}
        showStandardStreams = true
    }
}

注意:outputs.upToDateWhen {false} 不是必须的但如果没有使用,你需要运行 cleanTesttest 任务之前的 code> 或 clean 任务.

Notice: outputs.upToDateWhen {false} is not necessary but if not used, you need to run cleanTest or clean task before test task.

有关更多信息和选项,请参阅文档.

For more info and options see the documentation.

这篇关于Gradle:如何将测试 STDERR/STDOUT 的输出输出到控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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