[Gradle](EN) Show test results after gradle build or test
Show test results after gradle build or test
Environment and Prerequisite
- Gradle
- Assume that test environment is set
Method
Add below testLogging part to test in build.gradle
test {
useJUnitPlatform()
testLogging {
afterSuite { testDescriptor, testResult ->
if (testDescriptor.parent == null) {
println "Results: ${testResult.resultType} (${testResult.testCount} tests, ${testResult.successfulTestCount} successes, ${testResult.failedTestCount} failures, ${testResult.skippedTestCount} skipped)"
}
}
}
}
afterSuite
: Run after test suite is donetestDescriptor
: Describes a testtestResult
: Describes a test resulttestDescriptor.parent == null
: Run when TestDescriptor’s parent is null which means end of the tests
Result Example
Taewoo-Macbook-Air-M1-2020:SpringBatchTestExample taewoo$ ./gradlew build
...
> Task :test
...
Results: SUCCESS (6 tests, 6 successes, 0 failures, 0 skipped)
...
BUILD SUCCESSFUL in 10s
6 actionable tasks: 3 executed, 3 up-to-date
Reference
- https://stackoverflow.com/questions/37173218/how-to-configure-gradle-to-output-total-number-of-tests-executed
- https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:afterSuite(groovy.lang.Closure)
- https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/TestDescriptor.html
- https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/TestResult.html