jacoco-android-gradle-plugin icon indicating copy to clipboard operation
jacoco-android-gradle-plugin copied to clipboard

Results are different to Android Studio coverage

Open behelit opened this issue 8 years ago • 8 comments

Results are different to Android Studio coverage. For example, if I run the built in version with the 'coverage' button for unit tests, my results are 100%, but in the jacocoTestDebugUnitTestReport, it will be something like 62%

Why are they different? Please note, the other functions in this class are 100% in both AS/aturdm

arturdm plugin on top, Android Studio built in coverage on bottom Example

behelit avatar Apr 27 '16 00:04 behelit

Hi @behelit,

could you provide a sample project that reproduces this issue e.g. by extracting this class and its test class or forking https://github.com/codecov/example-android and adding this code there?

There's just too many possibilities why this could be happening.

arturdm avatar Apr 27 '16 17:04 arturdm

I don't have the same test but I've created a new project which shows as 100% coverage for the StringUtils class in Android Studio while the generated report displays 0%. Project is available from here: Jacoco Plugin Issue Demo

behelit avatar May 01 '16 23:05 behelit

I'm experiencing a similar issue where the IntelliJ IDEA coverage runner will report higher percentages than JaCoCo. In some cases IntelliJ will report 98% coverage and JaCoCo will report just 1%. I get the feeling this has to do with using PowerMock (and perhaps Mockito) and the solutions I've found online all suggest running JaCoCo in offline instrumentation. At the moment I don't have a ton of experience with configuring JaCoCo (reason I'm using this plugin), I was wondering if you had any advice on how I might enable offline instrumentation with this plugin? I can test on my project and then report back if it helped resolve the issue.

Thanks!

CodyEngel avatar Aug 11 '16 14:08 CodyEngel

For me, androidTest folder isn't covered by jacoco. Could that be the reason?

fouady avatar Sep 20 '16 16:09 fouady

Same for robolectric tests. They don't show-up in the coverage report, even though the IntelliJ IDEA reports as coverage for the robolectric-tested classes.

bazyle avatar Nov 29 '17 15:11 bazyle

@bazyle I had the same issue. The solution in this post worked for me, though the results still differ slightly from the IntelliJ coverage report.

crx-au avatar Dec 11 '17 00:12 crx-au

@crx-au Thanks. It worked for me as well. Looks like it's the jacoco version. I used version 0.7.9 from the same repo. For me it reported very accurate - 100%.

UPDATE: These are the only changes I've made to the gradle file(works with the bundled version of jacoco/no explicit version):

apply plugin: 'jacoco'
android {
     testOptions {
        unitTests {
            includeAndroidResources = true
            returnDefaultValues = true
        }
        unitTests.all {
            jacoco {
                includeNoLocationClasses = true
            }
        }
    }
}

bazyle avatar Dec 19 '17 14:12 bazyle

Im seeing the same issue here and using different jacoco versions doesnt seem to affect the results.

ardevd avatar Mar 22 '18 12:03 ardevd