Gradle Jacoco Plugin Displaying Zero Coverage

I am getting zero code coverage listed in the selected class group when running the Jacoco plugin Gradle. I have verified that all unit tests that test these classes have run successfully.

What's really interesting is that EclEmma, ​​in Eclipse, generates the correct code coverage results. I have verified that both tools use the same Jacoco version.

I am trying to figure out what is the difference between these two tools? Do I need any additional configuration for the Jacquo Gradle plugin.

Edit: My Gradle Jacoco's output shows: "The execution data for class com / .... does not match"

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

+4


source to share


3 answers


This probably means the jacoco plugin is misconfigured in gradle. You can find a checklist of common bugs with Jacoco and gradle here (Thanks to Taihu Kim): fooobar.com/questions/152088 / ...

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
    }
}

      

+2


source


I had the same problem when switching to gradle wrapper, but jacoco kept working with gradle. Running jacoco with gradle wrapper solved the problem.



fooobar.com/questions/621993 / ... helped me figure out what I was missing.

0


source


Also make sure the unit tests are actually running. If you have jar hell with Junit5 it can fail silently. Add --info

and check error messages.

0


source







All Articles