简体   繁体   中英

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

在此处输入图片说明

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?

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

根据我的经验,如果任何一个测试用例失败,那么我们将获得覆盖率为0%的报告,请确保您的所有测试都通过了

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM