Gradle Jacoco Plugin Reporting Zero Coverage
Asked Answered
U

4

7

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.

Utile answered 21/5, 2015 at 19:44 Comment(0)
O
2

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://mcmap.net/q/381860/-how-do-i-get-a-jacoco-coverage-report-using-android-gradle-plugin-0-10-0-or-higher

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
    }
}
Orchestral answered 21/5, 2015 at 19:59 Comment(3)
Unfortunately that did not work. I should clarify that the files do show up in the reports; however, they show no code being hit. EclEmma does show the code being hit. I'm wondering if this is a Java 8 issue with the Gradle Jacoco plugin. The files with problems all use Java 8 streams. ThanksUtile
Sorry I misread the question, I thought none of the classes was showing code coverage. You did use Jacoco 0.7.2 or later? That's when they added support for lambda expressions. Here is the changelog of Jacoco: eclemma.org/jacoco/trunk/doc/changes.htmlOrchestral
Yes we are using 0.7.5. We just tried switching from lambdas to double colons and this fixed the problem. The newest versions of jacoco are supposed to handle lambdas, so i'm not sure what the problem is. I posted in the Gradle forums, so i'll see what they say. Thanks!Utile
L
0

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

This stackoverflow accepted answer helped me figure out what I missed.

Letrice answered 10/1, 2016 at 10:54 Comment(0)
X
0

Also check that the unit tests actually run. If you have jar hell with Junit5, it might silently fail. Add --info and check for error messages.

Xuthus answered 20/8, 2019 at 13:12 Comment(0)
B
0

I followed this medium guide:

https://medium.com/codex/software-engineering-done-right-2358ae0d6dd4

and into test/jacoco I added include param with my package like this

test{
    ...
    jacoco {
        destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
        includes= ["it.funds.*"]
        classDumpDir = file("$buildDir/jacoco/classpathdumps")
    }
    ...
}
Blais answered 18/2, 2022 at 15:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.