In my JaCoCo code coverage reports for my espresso tests, all lines and branches are missed. I am using JaCoCo in an Android application which is built with gradle 1.5.0.
My gradle configuration:
apply plugin: 'jacoco'
android {
buildTypes {
debug {
testCoverageEnabled = true
}
}
}
jacoco {
version '0.7.5.201505241946'
}
I followed this blog post: Test coverage report for Android application.
When I run createDebugCoverageReport
, the report is generated in the correct folder (build/reports/coverage/flavor/debug/index.html). However, when I open the coverage report, my code coverage is 0% on every instructions and branches. Everything is "missed".
First I thought that the problem could be the location of the source code and test code, but they are located in /src/main/java/
and /src/androidTest/java/
Anyone has an idea how to fix this?
On some newer Samsung devices, when you run the Jacoco gradle task createDebugCoverageReport or createDebugAndroidTestCoverageReport, 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.
I have a workflow process class and a junit test class for it. Junit tests run successfully. However, Jacoco reports 0% coverage. It seems to ignore this class because of the annotation:
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.
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 or createDebugAndroidTestCoverageReport, it will run the unit tests, but show 0% coverage.
As per my experience if any one test case fails then we get coverage report with 0% make sure all your tests passes
My personal experience with Jacoco has not been good. It doesn't cover properly, and when it does it doesn't update the coverage as new tests are added.
I have just removed it, there doesn't seem to be support for Jacoco.
For your question though, according to @kolargol00:
Any particular reason why you are using an outdated version of the JaCoCo plugin? For Java 8 support, you have to use at least version 0.7.0 (see changelog).
In your configuration, the report goal is bound to the verify phase, so running mvn test
won't generate any report because it does not run the verify phase (test phase comes before verify). You have to use mvn verify
to execute tests and generate the report.
The JaCoCo project provides example Maven configurations. You can try "this POM file for a JAR project runs JUnit tests under code coverage and creates a coverage report".
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