Android Jacoco Coverage Shows 0% With Gradle However There Are 95% Tests Covering Code
Solution 1:
I had the exact same problem. But using the comment from Guna (27 Feb 2017), it seems that the problem is caused by running the coverage tests on some Samsung devices.
On some newer Samsung devices, when you run the Jacoco gradle task
createDebugCoverageReport
orcreateDebugAndroidTestCoverageReport
, it will run the unit tests, but show 0% coverage.But on a Google Nexus 5 or most emulators, when you run the same Jacoco task, it will work fine and show the correct coverage. Older Samsung devices also work well.
It's very odd.
Also remember to ensure that all your tests pass first. This is another limitation of Jacoco, because even if one small test fails in your whole suite, it will not generate a test coverage report. Another note: Your app may be automatically uninstalled when the coverage report is generated. Unknown reason why - you'll just have to reinstall it.
Update, 11 October 2018: There is a way to generate a coverage report even if an individual test fails. Use this in your app/build.gradle (from here):
buildTypes {
debug {
testCoverageEnabled = true
}
}
project.gradle.taskGraph.whenReady {
connectedDebugAndroidTest {
ignoreFailures = true
}
}
Automated build scripts may need to use the "--continue"
flag, to ensure a unit test failure will continue the gradle task; something like this:
./gradlew createDebugCoverageReport --continue
Further info, see also:
- https://web.archive.org/web/20171210224809/http://blog.wittchen.biz.pl/test-coverage-report-for-android-application (also view the user comments)
- http://wittchen.io/posts/test-coverage-in-android-applications/ (same article as above, but without the user comments)
- Ignore Gradle Build Failure and continue build script?
- http://mrhaki.blogspot.com/2014/12/gradle-goodness-continue-build-even.html
Solution 2:
Generation of coverage for your project using command
./gradlew clean createDebugCoverageReport
works just fine:
The only thing that I changed - is compileSdkVersion
from 23
to 25
and buildToolsVersion
from 23.0.1
to 25.0.2
, because this is the versions that I have.
Post a Comment for "Android Jacoco Coverage Shows 0% With Gradle However There Are 95% Tests Covering Code"