Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kotlin multiplatform coverage? [closed]

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?

like image 437
nwillc Avatar asked Jan 18 '20 16:01

nwillc


2 Answers

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
like image 86
Victor Harlan Lacson Avatar answered Oct 05 '22 06:10

Victor Harlan Lacson


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

like image 27
Petrus Nguyễn Thái Học Avatar answered Oct 05 '22 05:10

Petrus Nguyễn Thái Học