Android- Jacoco - combined report for both test and androidTest could not be generated

550 views Asked by At

In my current project, I have written local test and espresso test and I am trying to generate common code coverage report. I've added jacoco (com.hiya.jacoco-android) and executed a task that produces two separate reports instead of a combined report. Can you assist me in resolving this issue? I attempted to use "org.jacoco:org.jacoco.core", but it didn't generate a test report for my local unit test case. Additionally, the exclude classes functionality doesn't seem to work in either case.

Below is the task that I have created.

plugins {
    id 'com.hiya.jacoco-android'
}

jacoco {
    toolVersion = "$jacocoVersion"
    reportsDirectory = file("$buildDir/reports/coverage")
}

tasks.withType(Test) {
    jacoco.includeNoLocationClasses = true
    jacoco.excludes = ['jdk.internal.*']
}

task jacocoCombinedTestReports(type: JacocoReport, dependsOn: ['jacocoTestReport', 'createDebugCoverageReport']) {
    group = "Verification"
    description = "Creates JaCoCo test coverage report for Unit and Instrumented Tests (combined) on the Debug build"
    reports {
        xml.enabled = true
        html.enabled = true
    }

    // Files to exclude:
    // Generated classes, platform classes, etc.
    def excludes = [
            '**/R.class',
            '**/R$*.class',
            '**/BuildConfig.*',
            '**/Manifest*.*',
            '**/*Test*.*',
            'android/**/*.*',
            '**/*_Factory*.*',
            '**/*_Impl.class',
            '**/*$ViewInjector*',
            '**/*$Lambda$*',
            '**/*$inlined$*',
            '**/*$Synthetic*'
    ]

    /*def debugTree = fileTree(
            dir: "$project.buildDir/tmp/kotlin-classes/debug",
            excludes: excludes
    )
    def mainSrc = "$project.projectDir/src/main/java"

    sourceDirectories.from(files([mainSrc]))
    classDirectories.from(files([debugTree]))*/

    // generated classes
    classDirectories.from = fileTree(
            dir: "$buildDir/intermediates/classes/debug",
            excludes: excludes
    ) + fileTree(
            dir: "$buildDir/tmp/kotlin-classes/debug",
            excludes: excludes
    )
    // sources
    sourceDirectories.from = [
            android.sourceSets.main.java.srcDirs,
            "src/main/kotlin"
    ]

    executionData.from = fileTree(dir: project.buildDir, includes: [
    
            'jacoco/*.exec',
            'outputs/code_coverage/debugAndroidTest/connected/**/*.ec'
    ])
}

After executing the ./gradlew jacocoCombinedTestReports command in the terminal, the following reports are generated:

  1. The local test report can be found at app\build\jacoco.
  2. The Android Test Report is located at app\build\reports\coverage\androidTest\phase1icertis\debug.
  3. The combined report can be found at app\build\reports\coverage\jacocoCombinedTestReports.

However, it should be noted that in the third report, "No class files specified" is generated. Please let me know if I missed any steps or made any errors in the process.

0

There are 0 answers