Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Jacoco Plugin Reporting Zero Coverage

I'm getting zero code coverage reported on a select group of classes, when running Gradle's Jacoco plugin. I have confirmed all unit tests, which tests these classes, have successfully ran.

What is very interesting, is that EclEmma, in Eclipse, generates correct code coverage results. I have confirmed both tools are using the same version of Jacoco.

I'm trying to figure out what the difference between the two tools are? Do i need additonal configuration of the Gradle Jacoco plugin.

Edit: My Gradle Jacoco output is showing "Execution data for class com/.... does not match"

Update: I opened the test.exec file Jacoco generates, in Eclipse. It shows the classes with missing coverage having 80% of their probes executed.

like image 483
Eric Avatar asked May 21 '15 19:05

Eric


1 Answers

This probably means that the jacoco plugin isn't configured correctly in gradle. Here you can find a checklist of common errors with Jacoco and gradle (Thanks to Taeho Kim's clear answer): https://stackoverflow.com/a/23965581/2166900

Also, here is the configuration that I used in my last Android project and that worked for me:

apply plugin: 'jacoco'

jacoco {
    toolVersion = "0.7.2.+"
}

def coverageSourceDirs = [
        'src/main/java'
]

task jacocoTestReport(type:JacocoReport, dependsOn: "testDebug") {
    group = "Reporting"

    description = "Generate Jacoco coverage reports"

    classDirectories = fileTree(
            dir: 'build/intermediates/classes/debug',
            excludes: ['**/R.class',
                       '**/R$*.class',
                       '**/*$ViewInjector*.*',
                       '**/BuildConfig.*',
                       '**/Manifest*.*']
    )

    additionalSourceDirs = files(coverageSourceDirs)
    sourceDirectories = files(coverageSourceDirs)
    executionData = files('build/jacoco/testDebug.exec')

    reports {
        xml.enabled = false
        html.enabled = true
    }
}
like image 140
GoGoris Avatar answered Sep 27 '22 19:09

GoGoris