我想看测试结果(系统)。out/err,来自正在测试的组件的日志消息),因为它们运行在我运行的同一控制台:
gradle test
不要等到测试完成才查看测试报告(测试报告仅在测试完成时生成,因此在运行测试时不能“尾部-f”任何内容)
我想看测试结果(系统)。out/err,来自正在测试的组件的日志消息),因为它们运行在我运行的同一控制台:
gradle test
不要等到测试完成才查看测试报告(测试报告仅在测试完成时生成,因此在运行测试时不能“尾部-f”任何内容)
当前回答
添加此构建。Gradle停止Gradle吞下stdout和stderr。
test {
testLogging.showStandardStreams = true
}
这里有记录。
其他回答
只需将以下闭包添加到build.gradle中。每次测试执行之后,输出都会被打印出来。
test{
useJUnitPlatform()
afterTest { desc, result ->
def output = "Class name: ${desc.className}, Test name: ${desc.name}, (Test status: ${result.resultType})"
println( '\n' + output)
}
}
对于Android,这很有效:
android {
...
testOptions {
unitTests.all {
testLogging {
outputs.upToDateWhen { false }
events "passed", "failed", "skipped", "standardError"
showCauses true
showExceptions true
}
}
}
}
请参见从控制台运行Android单元/检测测试
'test'任务不适用于Android插件,对于Android插件使用以下方法:
// Test Logging
tasks.withType(Test) {
testLogging {
events "started", "passed", "skipped", "failed"
}
}
详见:https://stackoverflow.com/a/31665341/3521637
您可以在构建中添加Groovy闭包。Gradle文件,为您做日志记录:
test {
afterTest { desc, result ->
logger.quiet "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
}
}
在你的控制台上,它是这样的:
:compileJava UP-TO-DATE
:compileGroovy
:processResources
:classes
:jar
:assemble
:compileTestJava
:compileTestGroovy
:processTestResources
:testClasses
:test
Executing test maturesShouldBeCharged11DollarsForDefaultMovie [movietickets.MovieTicketsTests] with result: SUCCESS
Executing test studentsShouldBeCharged8DollarsForDefaultMovie [movietickets.MovieTicketsTests] with result: SUCCESS
Executing test seniorsShouldBeCharged6DollarsForDefaultMovie [movietickets.MovieTicketsTests] with result: SUCCESS
Executing test childrenShouldBeCharged5DollarsAnd50CentForDefaultMovie [movietickets.MovieTicketsTests] with result: SUCCESS
:check
:build
从1.1版本开始,Gradle支持更多的选项来记录测试输出。有了这些选项,你可以通过以下配置实现类似的输出:
test {
testLogging {
events "passed", "skipped", "failed"
}
}
免责声明:我是Gradle Test Logger Plugin的开发者。
你可以简单地使用Gradle Test Logger Plugin在控制台上打印漂亮的日志。该插件使用合理的默认值,以满足大多数用户很少或没有配置,但也提供了许多主题和配置选项,以满足每个人。
例子
标准的主题
摩卡主题
使用
plugins {
id 'com.adarshr.test-logger' version '<version>'
}
确保你总是从Gradle Central获得最新版本。
配置
你根本不需要任何配置。然而,该插件提供了一些选项。可以这样做(默认值显示):
testlogger {
// pick a theme - mocha, standard, plain, mocha-parallel, standard-parallel or plain-parallel
theme 'standard'
// set to false to disable detailed failure logs
showExceptions true
// set to false to hide stack traces
showStackTraces true
// set to true to remove any filtering applied to stack traces
showFullStackTraces false
// set to false to hide exception causes
showCauses true
// set threshold in milliseconds to highlight slow tests
slowThreshold 2000
// displays a breakdown of passes, failures and skips along with total duration
showSummary true
// set to true to see simple class names
showSimpleNames false
// set to false to hide passed tests
showPassed true
// set to false to hide skipped tests
showSkipped true
// set to false to hide failed tests
showFailed true
// enable to see standard out and error streams inline with the test results
showStandardStreams false
// set to false to hide passed standard out and error streams
showPassedStandardStreams true
// set to false to hide skipped standard out and error streams
showSkippedStandardStreams true
// set to false to hide failed standard out and error streams
showFailedStandardStreams true
}
我希望你会喜欢使用它。