Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

0% code coverage on espresso tests with JaCoCo and Gradle

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".

enter image description here

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?

like image 377
Hans Leautaud Avatar asked Feb 11 '16 11:02

Hans Leautaud


People also ask

Does JaCoCo Gradle work on Android 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. 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.

Does JaCoCo report 0% coverage for workflow process class?

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:

What are some of the limitations of JaCoCo?

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.

Why does JaCoCo Show 0% coverage on some Samsung devices?

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.


2 Answers

As per my experience if any one test case fails then we get coverage report with 0% make sure all your tests passes

like image 98
anuja jain Avatar answered Nov 15 '22 05:11

anuja jain


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:

Answer

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".

like image 22
TejjD Avatar answered Nov 15 '22 04:11

TejjD