2016-09-15 56 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