We would like to use Gradle in conjunction with Kotlin and Jacoco (+JUnit 5) for generating a code coverage report.
Our project directory tree looks as follows:
project/{src,test}/main/kotlin ...
Our build.gradle file looks as follows:
jacoco {
toolVersion = "0.7.9"
reportsDir = file("$buildDir/reports")
applyTo junitPlatformTest
}
jacocoTestReport {
group = "Reporting"
description = "Generate Jacoco coverage report."
classDirectories = fileTree(
dir: "$buildDir/classes/kotlin/main"
)
def coverageSourceDirs = [
"src/main/kotlin"
]
additionalSourceDirs = files(coverageSourceDirs)
sourceDirectories = files(coverageSourceDirs)
executionData = files("$buildDir/jacoco/junitPlatformTest.exec")
reports {
xml.enabled = true
html.enabled = true
csv.enabled = true
}
}
test {
jacoco {
append = false
destinationFile = file("$buildDir/jacoco/junitPlatformTest.exec")
includeNoLocationClasses = true
}
}
test.dependsOn junitPlatformTest
With this configuration, Jacoco generates a html report and puts it under build/reports/test/html
. However, it shows me 0% coverage. This should not be the case, because I have one test case that excercices all methods for a single dummy class in the project.
I went through several posts such as:
- http://vgaidarji.me/blog/2017/12/20/how-to-configure-jacoco-for-kotlin-and-java-project/
- Jacoco is reporting 0 coverage of Kotlin classes by unit tests, in an Android project
- JaCoCo returning 0% Coverage with Kotlin and Android 3.0
However, I could not quite find a solution that worked for me, yet.