Sunday, April 8, 2018

Gradle – Display test results in Console

By default, the test result will not display in the console.

$ gradle test

Starting a new Gradle Daemon for this build (subsequent builds will be faster).
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE

BUILD SUCCESSFUL

Total time: 7.78 secs
Copy
P.S The Gradle test report will be generated in $project/build/reports/index.html

1. Display test result
To diplay the test result in console, add the following test events :
build.gradle
test {
//we want display the following test events
    testLogging {
        events "PASSED", "STARTED", "FAILED", "SKIPPED"
    }
}
Copy
Run the test process again, the test classes, methods and status will be displayed.

$ gradle clean test

:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE

com.mkyong.helloworld.TestController > test_welcome2 STARTED

com.mkyong.helloworld.TestController > test_welcome2 PASSED

//...

BUILD SUCCESSFUL

Total time: 7.78 secs
Copy

2. Extra
Review a Gradle testLogging example from the official documentation

build.gradle

apply plugin: 'java'

test {
    testLogging {
        // set options for log level LIFECYCLE
        events "failed"
        exceptionFormat "short"

        // set options for log level DEBUG
        debug {
            events "started", "skipped", "failed"
            exceptionFormat "full"
        }

        // remove standard output/error logging from --info builds
        // by assigning only 'failed' and 'skipped' events
        info.events = ["failed", "skipped"]
    }
}

No comments:

Post a Comment

உப்பு மாங்காய்

சுருக்குப்பை கிழவி. சுருக்கங்கள் சூழ் கிழவி. பார்க்கும் போதெல்லாம் கூடையுடனே குடியிருப்பாள். கூடை நிறைய குட்டி குட்டி மாங்காய்கள். வெட்டிக்க...