Multiplatform test summary

Usually when writing tests in a Gradle project I add something like this to the build file so I can get an overview of how many tests passed/failed/etc.:

test {
    useJUnitPlatform()
    testLogging {
        events "passed", "skipped", "failed"
        exceptionFormat "full"
    }
    afterSuite { desc, result ->
        if (!desc.parent) {
            println "-" * 80
            println "Test results: ${result.resultType} " +
                    "(" +
                    "${result.testCount} tests, " +
                    "${result.successfulTestCount} successful, " +
                    "${result.failedTestCount} failed, " +
                    "${result.skippedTestCount} skipped" +
                    ")"
        }
    }
}

Unfortunately, when I run allTests in my MPP project, there is no extra output and I cannot find any provided way of achieving anything similar.

Is there a way to output a nice test summary in a multiplatform project?

allTests is an aggregating task of type KotlinTestReport that extends Gradle’s TestReport task and generates a summarized test report for all platforms after separate test tasks for each target platform have run. It’s not a test task, so you can’t configure it as you used to configure single platform tests. You can however configure each of the latter test tasks using tasks.withType function:

tasks.withType(AbstractTestTask) {
    testLogging { ... }
    afterSuite { ... }
}

Then each platform test task will output its own summary like

--------------------------------------------------------------------------------
Test results: FAILURE (117 tests, 116 successful, 1 failed, 0 skipped)
1 Like