I'm getting zero code coverage reported on a select group of classes, when running Gradle's Jacoco plugin. I have confirmed all unit tests, which tests these classes, have successfully ran.
What is very interesting, is that EclEmma, in Eclipse, generates correct code coverage results. I have confirmed both tools are using the same version of Jacoco.
I'm trying to figure out what the difference between the two tools are? Do i need additonal configuration of the Gradle Jacoco plugin.
Edit: My Gradle Jacoco output is showing "Execution data for class com/.... does not match"
Update: I opened the test.exec file Jacoco generates, in Eclipse. It shows the classes with missing coverage having 80% of their probes executed.
This probably means that the jacoco plugin isn't configured correctly in gradle. Here you can find a checklist of common errors with Jacoco and gradle (Thanks to Taeho Kim's clear answer): https://stackoverflow.com/a/23965581/2166900
Also, here is the configuration that I used in my last Android project and that worked for me:
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.7.2.+"
}
def coverageSourceDirs = [
'src/main/java'
]
task jacocoTestReport(type:JacocoReport, dependsOn: "testDebug") {
group = "Reporting"
description = "Generate Jacoco coverage reports"
classDirectories = fileTree(
dir: 'build/intermediates/classes/debug',
excludes: ['**/R.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/BuildConfig.*',
'**/Manifest*.*']
)
additionalSourceDirs = files(coverageSourceDirs)
sourceDirectories = files(coverageSourceDirs)
executionData = files('build/jacoco/testDebug.exec')
reports {
xml.enabled = false
html.enabled = true
}
}
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