0% code coverage on espresso tests with JaCoCo and

2019-04-07 19:44发布

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?

2条回答
我命由我不由天
2楼-- · 2019-04-07 20:13

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

查看更多
一夜七次
3楼-- · 2019-04-07 20:34

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

查看更多
登录 后发表回答