Code Coverage not reported for instrumented tests (Android library module) on AGP 7.0
See original GitHub issueHi I’m trying this on my test multi-module project before trying this on the other project I’m working on. I’ve followed the steps and run ./gradlew rootCoveragePlugin
but got this report:

– com.raquezha.heograpiya.splash is 0% but when I run it in Android Studio local coverage it recognize the tests:

–
here’s the file structure as you can see Android Studio recognizes the local code coverage of splash module and says its 100% lines covered

here’s my top-level build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
apply from: rootProject.file('dependencies.gradle')
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0-alpha15'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0'
classpath 'com.google.gms:google-services:4.3.5'
classpath 'nl.neotech.plugin:android-root-coverage-plugin:1.4.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
plugins {
id "nl.neotech.plugin.rootcoverage" version "1.4.0"
}
apply plugin: 'nl.neotech.plugin.rootcoverage'
jacoco {
toolVersion = "0.8.7"
}
tasks.withType(Test) {
useJUnitPlatform()
testLogging {
exceptionFormat "full"
events "started", "skipped", "passed", "failed"
showStandardStreams true
}
}
subprojects {
afterEvaluate { project ->
if (project.hasProperty('android')) {
android {
compileSdk 30
buildToolsVersion "30.0.3"
defaultConfig {
minSdk 26
targetSdk 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
sourceSets {
main {
java.srcDirs = ['src/main/kotlin']
}
androidTest {
java.srcDirs = ['src/androidTest/kotlin']
}
test {
java.srcDirs = ['src/test/kotlin']
}
}
}
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
here’s the splash module build.gradle:
plugins {
id 'com.android.library'
id 'kotlin-android'
}
dependencies {
implementation _libs.lottie
implementation project(':shared')
testImplementation project(path: ':shared', configuration: 'testDependencies')
androidTestImplementation project(path: ':shared', configuration: 'androidTestDependencies')
}
tasks.withType(Test) {
useJUnitPlatform()
testLogging {
exceptionFormat "full"
events "started", "skipped", "passed", "failed"
showStandardStreams true
}
}
I’m using:
- Android Studio Arctic Fox | 2020.3.1 Canary 15
- Gradle JDK: AdoptOpenj9-11
- gradle-wrapper: distributionUrl=https://services.gradle.org/distributions/gradle-7.0-bin.zip
I’m using canary because this is only a test project I want to test new stuff
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:24 (16 by maintainers)
Top Results From Across the Web
AGP 7.0.0 does not create unit test jacoco exec files correctly ...
Now that AGP 7.0.0 is stable, here's the current behavior I'm seeing, which still doesn't seem correct: For library modules, with testCoverageEnabled true ......
Read more >Unit tests not working on Android Studio Arctic Fox
Go to Toolbar > Run > Edit Configurations · Then create a new configuration under Gradle with tasks for the tests you want...
Read more >Test in Android Studio
Android Studio is designed to make testing simple. It contains many features to simplify how you create, run, and analyze tests.
Read more >Android code coverage using JaCoCo | by Radhika S - Canopas
2. Set up Jacoco configuration · variantName.capitalize()} · UnitTest" // Add unit test coverage tasks tasks. · testTaskName · Coverage", type: JacocoReport, ...
Read more >Android User Guide - Google Samples
Try using the latest versions of lint (the Android Gradle plugin), as well as of Gradle — even if that means using a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Update:
It seems Google finally stepped in and fixed the issue in AGP version 7.2.0: https://issuetracker.google.com/issues/195860510#comment12
Unfortunately the fix will not be released this month, they expect to release a beta version of AGP 7.2.0 that includes this fix around December 13th.
Hi @raquezha took me a while to take a look at this, but I found a few things:
Looking at the report that is generated, it is missing all execution data, which is needed to calculate coverage. You can check this for your self by going to the sessions part of the report:
This can have multiple causes, but in this case this happens because the Android Gradle Plugin updated where these files are located since version 7.0. This means the Plugin needs a small update.
However I also spotted this, which will also prevent coverage (even if I update the plugin):
TLDR: This plugin needs an update due to changes in the Android Gradle Plugin 7.0. I’m going to take care of this.(see update this is no longer something I can fix)