kotlin multiplatform coverage? [closed]
Asked Answered
B

2

11

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?

Both answered 18/1, 2020 at 16:12 Comment(1)
I just opened a feature request for this on IDEA's bugtracker: youtrack.jetbrains.com/issue/IDEA-241030Exile
F
8

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
Fugere answered 23/6, 2020 at 0:23 Comment(1)
@Both do not hesitate to mark an answer as correct if it helped you!Knorring
K
0

try this: https://github.com/Kotlin/kotlinx-kover (Gradle plugin for Kotlin code coverage agents: IntelliJ and JaCoCo.)

Khalkha answered 13/11, 2021 at 13:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.