[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 done
  • testDescriptor: Describes a test
  • testResult: Describes a test result
  • testDescriptor.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