当我运行gradle测试时,输出如下:
:test
> Building 80% > :test > 86 tests completed
并重新排列> Building 80% > :test > 86 tests completed
行,因为它正在向前发展。
我想要的是阻止gradle替换这一行并逐行输出,例如:
:test
:test > 86 tests completed
:test > 87 tests completed
:test > 88 tests completed
有没有办法做到这一点?
答案 0 :(得分:0)
您可以配置test
块
apply plugin: 'java'
repositories {
jcenter()
}
dependencies {
testCompile 'junit:junit:4.12'
}
test {
// show standard out and standard error of the test JVM(s) on the console, without this
// the text output printed by the tests won't show.
// ref: https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html
testLogging.showStandardStreams = true
def testCount = 0
afterTest { descriptor, result ->
// descriptor is of type TestDescriptor, result is of type TestResult
// ref: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/TestDescriptor.html
// ref: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/TestResult.html
logger.lifecycle("Test {count: ${++testCount} name: $descriptor.name result: $result.resultType}")
}
}
然后您将在测试任务期间看到您的输出。当然,根据您的需要,您可以使用其他日志记录级别,但info
,debug
,error
也可用。除非lifecycle
命令行arg被传递,否则-q
将始终显示。
$ ./gradlew clean test
Configuration on demand is an incubating feature.
:clean
:compileJava
:processResources UP-TO-DATE
:classes
:compileTestJava
:processTestResources UP-TO-DATE
:testClasses
:test
Test {count: 1 name: testSomeLibraryMethod result: SUCCESS}
BUILD SUCCESSFUL
Total time: 1.229 secs