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 skipped. I am using JaCoCo in an Android application that is built using 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 Report for Android App .

When I run createDebugCoverageReport , the report is created in the correct folder (build / reports / coverage / flavor / debug / index.html). However, when I open the coverage report, my code is 0% for each instruction and branches. Everything is "skipped."

enter image description here

At first I thought the problem might be with the source code and the test code, but they are located in /src/main/java/ and /src/androidTest/java/

Anyone have an idea how to fix this?

+6
source share
2 answers

My personal experience with Jacoco was not good. It does not distribute properly, and when it does, it does not update coverage when new tests are added.

I just uninstalled it, it seems Jacoco support is not supported.

For your question though, according to @ kolargol00 :

Respond

Any specific reason why you are using an outdated version of the JaCoCo plugin? To support Java 8, you need to use at least version 0.7.0 (see the changelog ).

In your configuration, the purpose of the report is tied to the verification phase, so running mvn test will not generate any report because it does not start the verification phase ( before verification ). You must use mvn verify to run tests and create a report.

The JaCoCo project provides sample Maven configurations. You can try " this POM file for a JAR project runs JUnit tests under code protection and generates a coverage report .

+1
source

According to my experience, if any one test case fails, we get a coverage report with 0%, make sure all your tests pass

+1
source

All Articles