jacoco-android-gradle-plugin
jacoco-android-gradle-plugin copied to clipboard
Results are different to Android Studio coverage
Results are different to Android Studio coverage. For example, if I run the built in version with the 'coverage' button for unit tests, my results are 100%, but in the jacocoTestDebugUnitTestReport, it will be something like 62%
Why are they different? Please note, the other functions in this class are 100% in both AS/aturdm
arturdm plugin on top, Android Studio built in coverage on bottom
Hi @behelit,
could you provide a sample project that reproduces this issue e.g. by extracting this class and its test class or forking https://github.com/codecov/example-android and adding this code there?
There's just too many possibilities why this could be happening.
I don't have the same test but I've created a new project which shows as 100% coverage for the StringUtils class in Android Studio while the generated report displays 0%. Project is available from here: Jacoco Plugin Issue Demo
I'm experiencing a similar issue where the IntelliJ IDEA coverage runner will report higher percentages than JaCoCo. In some cases IntelliJ will report 98% coverage and JaCoCo will report just 1%. I get the feeling this has to do with using PowerMock (and perhaps Mockito) and the solutions I've found online all suggest running JaCoCo in offline instrumentation. At the moment I don't have a ton of experience with configuring JaCoCo (reason I'm using this plugin), I was wondering if you had any advice on how I might enable offline instrumentation with this plugin? I can test on my project and then report back if it helped resolve the issue.
Thanks!
For me, androidTest folder isn't covered by jacoco. Could that be the reason?
Same for robolectric tests. They don't show-up in the coverage report, even though the IntelliJ IDEA reports as coverage for the robolectric-tested classes.
@bazyle I had the same issue. The solution in this post worked for me, though the results still differ slightly from the IntelliJ coverage report.
@crx-au Thanks. It worked for me as well. Looks like it's the jacoco version. I used version 0.7.9 from the same repo. For me it reported very accurate - 100%.
UPDATE: These are the only changes I've made to the gradle file(works with the bundled version of jacoco/no explicit version):
apply plugin: 'jacoco'
android {
testOptions {
unitTests {
includeAndroidResources = true
returnDefaultValues = true
}
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}
}
}
Im seeing the same issue here and using different jacoco versions doesnt seem to affect the results.