Skip to content

Code Coverage not reported for instrumented tests (Android library module) on AGP 7.0 #36

Closed
@raquezha

Description

@raquezha

Hi 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:

Screen Shot 2021-05-07 at 5 17 43 PM

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

Screen Shot 2021-05-07 at 5 59 14 PM

--

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

Screen Shot 2021-05-07 at 6 08 57 PM

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:

  1. Android Studio Arctic Fox | 2020.3.1 Canary 15
  2. Gradle JDK: AdoptOpenj9-11
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions