Gradle:如何从测试STDERR / STDOUT获取输出到控制台? [英] Gradle: How to get output from test STDERR/STDOUT into console?
问题描述
(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
但是在这种情况下,第三方库的很多不需要的输出也是如此。
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
}
编辑:
更好的方法:
A better approach:
apply plugin: 'java'
test {
testLogging {
outputs.upToDateWhen {false}
showStandardStreams = true
}
}
注意: outputs.upToDateWhen {false}
是没有必要的,但如果不使用,输出只会显示,如果他们不是最新的,在这种情况下,你需要运行 cleanTest
或 clean >
test
任务之前的任务。
Notice: outputs.upToDateWhen {false}
is not necessary but if not used, outputs are only displayed if they're not up-to-date and in that case, you need to run cleanTest
or clean
task before test
task.
更多信息和选项请参阅文档。
For more info and options see the documentation.
这篇关于Gradle:如何从测试STDERR / STDOUT获取输出到控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!