JacocoEverywhere icon indicating copy to clipboard operation
JacocoEverywhere copied to clipboard

Jacoco coverage doesn't work with RobolectricTestRunner

Open paveldudka opened this issue 9 years ago • 7 comments

Seems like related to https://github.com/jacoco/jacoco/pull/288. Need to investigate

paveldudka avatar May 03 '16 03:05 paveldudka

From reading the linked issue, it looks like there are two options for getting this working:

  1. with gradle 2.13+, use jacoco 0.7.6+; or
  2. with older gradle, use jacoco 0.7.2

It's not clear to me how to change the jacoco version. Reading this plugin it looks like jacoco gets imported from android-build-tools. Looking at android examples, it looks like jacoco should be configurable in build.gradle like this:

jacoco {
    toolVersion '0.7.6'
}

but I haven't got this working yet.

alxndrsn avatar May 03 '16 14:05 alxndrsn

android {
    jacoco {
        version '0.7.6'
    }
}

has no effect either.

alxndrsn avatar May 03 '16 14:05 alxndrsn

Ah, the previous example was missing an equals sign. Should have read:

android {
    jacoco {
        version = '0.7.6'
    }
}

With this, I get the following error:

It is no longer possible to set the Jacoco version in the jacoco {} block.
To update the version of Jacoco without updating the android plugin,
add a buildscript dependency on a newer version, for example: buildscript{    dependencies {
        classpath"org.jacoco:org.jacoco.core:0.7.4.201502262128"    }}

However, adding this to build.gradle does not get tests working:

buildscript {
        repositories {
                ...
        }
        dependencies {
                ...
                classpath 'com.trickyandroid:jacoco-everywhere:0.2.1'
                classpath 'org.jacoco:org.jacoco.core:0.7.6.201602180812'
        }
}

alxndrsn avatar May 03 '16 14:05 alxndrsn

The following seems to work:

buildscript {
        ...
        configurations.all {
                resolutionStrategy {
                        // use old jacoco so Robolectric test coverage is included in reports
                        force 'org.jacoco:org.jacoco.core:0.7.2.201409121644'
                }
        }
 }

alxndrsn avatar May 03 '16 15:05 alxndrsn

Same problem here. The @alxndrsn solution also works here.

niltonvasques avatar Nov 14 '16 20:11 niltonvasques

Dear alxndrsn, I have met same issue like you. When I use JacocoEverywhere, coverage report doesn't include class which uses Robolectric. I have followed your above instruction but I still do not get coverage. Any updated source need ? Thank you

LuongChu12 avatar Nov 15 '16 10:11 LuongChu12

HI guys, tried the above mentioned fix for jacoco-everywhere from @alxndrsn , i get the following error " java.io.IOException: Incompatible version 1007.".

Please let me know if there is any other resolution for the same.

Thanks in advance

rakki043 avatar Apr 07 '17 10:04 rakki043