Is there any tool to measure test coverage in the common portion of a Kotlin multiplatform project? I'm investigating migrating a Kotlin project to multiplatform. I'm a TDD developer and the code has 98% coverage. A good 95% can move to common. Am I looking at abandoning coverage metrics?
I have also a multiplatform kotlin project that uses jacoco for test coverage.
just follow this guide
but there's a need for a little configuration in case you are using gradle kotlin dsl:
plugins {
    kotlin("multiplatform") version "1.3.72"
    id("java-library")
    jacoco
}
jacoco {
    toolVersion = "0.8.6"
}
tasks.jacocoTestReport {
    val coverageSourceDirs = arrayOf(
            "src/commonMain",
            "src/jvmMain"
    )
    val classFiles = File("${buildDir}/classes/kotlin/jvm/")
            .walkBottomUp()
            .toSet()
    classDirectories.setFrom(classFiles)
    sourceDirectories.setFrom(files(coverageSourceDirs))
    executionData
            .setFrom(files("${buildDir}/jacoco/jvmTest.exec"))
    reports {
        xml.isEnabled = true
        html.isEnabled = true
    }
}
running the command below will generate reports on your build/reports/test/jacoco
gradle clean build jacocoTestReport
                        try this: https://github.com/Kotlin/kotlinx-kover (Gradle plugin for Kotlin code coverage agents: IntelliJ and JaCoCo.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With