Code coverage for Instrumented test cases is 0

436 views
Skip to first unread message

Kanishak Gupta

unread,
Sep 22, 2022, 8:57:58 AM9/22/22
to JaCoCo and EclEmma Users
Hi all, 

I am trying to generate the code coverage for our android project. It comprises of both Unit test cases and Instrument Test Cases. But the coverage is generated only for Unit tests. 

In the html file, the Activity names are present, but the coverage is always zero. Could someone please help me figure out the issue, so that the UI test cases also reflect a coverage. 

Please find below the build.gradle implementation and gradle commands. 

'''
task jacocoTestReport(type: JacocoReport, dependsOn: ["testDebugUnitTest", "createDebugAndroidTestCoverageReport", "connectedAndroidTest"]) {
    group = "Reporting"
    description = "Generate Jacoco coverage reports"

    reports {
        xml.required = true
        html.required = true
    }

    def fileFilter = ['**/AndroidManifest.xml', '**/strings.xml', '**/*.xml', '**/*.json']
    def mainSrc = "${project.projectDir}"
    def kotlinTree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debugUnitTest", excludes: fileFilter)
    def kotlinUITree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debugAndroidTest", excludes: fileFilter)
    sourceDirectories.setFrom(files([mainSrc]))
    classDirectories.setFrom(files([kotlinTree, kotlinUITree]))
    executionData.setFrom(fileTree(dir: "$project.buildDir",
            includes: ['**/*.exec', '**/*.ec']
    ))
}
'''

gradlew connectedAndroidTest jacocoTestReport


Thank you in advance.

Jahan Backs

unread,
Oct 13, 2023, 4:28:21 AM10/13/23
to JaCoCo and EclEmma Users
Jacoco setting seems ok Just add 

buildTypes {
        debug {
            enableUnitTestCoverage true
            enableAndroidTestCoverage true
        }
    }

and report command is 
.\gradlew create{YOUR_TASK}CoverageReport
Reply all
Reply to author
Forward
0 new messages