Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android unit test coverage is always 0

First I added apply plugin: 'jacoco' in my gradle file.
Next, I activated unit test coverage in my gradle file by setting enableUnitTestCoverage to true:

    buildTypes {
        debug {
            applicationIdSuffix ".debug"
            signingConfig signingConfigs.debug
            enableUnitTestCoverage true
        }
    }

I ran the gradle task createDebugUnitTestCoverageReport using the gradle wrapper with this command: ./gradlew clean createDebugUnitTestCoverageReport

The code coverage report is generated but coverage percentage is always 0 whereas I have unit tests and when I run "Tests with coverage" in Android Studio my code coverage is not 0.

I use Android Gradle Plugin 7.4.2 (com.android.tools.build:gradle:7.4.2), Gradle 7.5 and Java 11. I use gradle with Groovy.

Do you know how can I fix this issue?

Thanks for your help

like image 628
B3n Avatar asked Dec 09 '25 08:12

B3n


1 Answers

Upgrading to Android Gradle Plugin 8.0.0 solved my issue. Maybe there is a bug with the version 7.4.2.
Keep in mind that AGP 8.0.0 requires java 17.

like image 79
B3n Avatar answered Dec 11 '25 22:12

B3n