I want to get line coverage in my source files for my test coverage results. The test results in the generated table have columns for missed lines, and even for missed control flows. According to stuff I've read, this means if the source files are found, I will be able to get line coverage displayed in my source files.
Currently, I have unit test results and android test results in separate reports. The android test results say "Source file "com/example/helloworld/KeyboardUtil.kt" was not found during generation of report."
This is the relevant part of the gradle.
jacoco {
toolVersion = jacoco_version
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
reports {
xml.enabled = true
html.enabled = true
csv.enabled = true
}
def fileFilter = ['android/databinding/**/*.class',
'**/android/databinding/*Binding.class',
'**/android/databinding/*',
'**/androidx/databinding/*',
'**/BR.*',
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'android/**/*.*',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/*_MembersInjector.class',
'**/Dagger*Component.class',
'**/Dagger*Component$Builder.class',
'**/*Module_*Factory.class',
'**/di/module/*',
'**/*_Factory*.*',
'**/*Module*.*',
'**/*Dagger*.*',
'**/*Hilt*.*',
'**/*MapperImpl*.*',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/BuildConfig.*',
'**/*Component*.*',
'**/*BR*.*',
'**/Manifest*.*',
'**/*$Lambda$*.*',
'**/*Companion*.*',
'**/*Module*.*',
'**/*Dagger*.*',
'**/*Hilt*.*',
'**/*MembersInjector*.*',
'**/*_MembersInjector.class',
'**/*_Factory*.*',
'**/*_Provide*Factory*.*',
'**/*Extensions*.*',
'**/*$Result.*',
'**/*$Result$*.*']
def debugTree = fileTree(dir: "${buildDir}/tmp/kotlin-classes/debug", excludes: fileFilter)
def mainSrc = fileTree(dir: "${projectDir}/src/main/java", excludes: fileFilter)
getSourceDirectories().setFrom(files([mainSrc]))
getClassDirectories().setFrom(files([debugTree]))
def unitTestsData = "$project.buildDir/jacoco/testDebugUnitTest.exec"
def androidTestsData = fileTree(dir: "${buildDir}/outputs/code_coverage/debugAndroidTest/connected/",
includes: ["**/*.ec"])
getExecutionData().setFrom(files([unitTestsData, androidTestsData]))
}
I believe the problem to be these lines:
def debugTree = fileTree(dir: "${buildDir}/tmp/kotlin-classes/debug", excludes: fileFilter)
def mainSrc = fileTree(dir: "${projectDir}/src/main/java", excludes: fileFilter)
getSourceDirectories().setFrom(files([mainSrc]))
getClassDirectories().setFrom(files([debugTree]))
The main src directory is correct, but in the report, the path to the result is "app > com.example.helloworld > KeyboardUtil" when it should be "app > src > main > java > com.example.helloworld > KeyboardUtil"
Not sure how to fix it.