2016-09-15 58 views
0

当我运行gradle这个测试中,它的输出如下: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

您可以配置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}") 
    } 
} 

然后你会看到测试任务期间,你的输出。当然,您可以根据您的需要设定另一个日志记录级别,但infodebug,error也可用。 lifecycle将始终显示,除非-q命令行arg通过。

$ ./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