Gradle: How to get output from the STDERR / STDOUT test to the console?

(Gradle 3.2.1) I run some java tests that register output in Stderr / Stdout. I can see this output if I run

gradle test --info 

but in this case, most of the unwanted output from 3 party libraries is also there.

The documentation suggests using logging.caputureStandardError / logging.caputureStandardError (loglevel) , but it seems to have no effect.

 tasks.withType(Test) { logging.captureStandardOutput LogLevel.QUIET logging.captureStandardError LogLevel.QUIET } 

Then, if the gradle test is gradle test , STDERR / STDOUT is not displayed in the console.

How can I get only the result from the test classes in the console?

+30
stdout stderr testing gradle
source share
2 answers

Add these lines to build.gradle :

 apply plugin: 'java' test { dependsOn cleanTest testLogging.showStandardStreams = true } 

Please note: dependsOn cleanTest not required, but if it is not used , you need to run the cleanTest or clean task before the test task.


Edit:

The best approach:

 apply plugin: 'java' test { testLogging { outputs.upToDateWhen {false} showStandardStreams = true } } 

Please note: outputs.upToDateWhen {false} not necessary, but if it is not used , you need to run the cleanTest or clean task before the test task.

For more information and options, see the documentation .

+48
source share

For those using Kotlin / Kotlin DSL for Gradle, you need to add the following to the build.gradle.kts file:

 tasks.withType<Test> { this.testLogging { this.showStandardStreams = true } } 

Also, as mentioned in another answer, you will need to run gradle clean test so that the output is output every time.

+2
source share

All Articles