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

Hi @ilya.gorbunov, I’m trying to log these results but I can’t seem to make this work, where do I need to add the tasks.withType(AbstractTestTask) { ... } code?

Anywhere at the top-level of a gradle build script.
Note that I gave this example in the Groovy script syntax (the same as in the question). With the Kotlin script, it would be something like tasks.withType<AbstractTestTask> { ... }

I tried that already yesterday but that didn’t work @ilya.gorbunov. When I run the multiplatform tests for all targets using ./gradlew check no results are logged on the console for the tests. Do I need to add something else apart from this?