JaCoCo doesn't work with Robolectric tests

前端 未结 5 539
Happy的楠姐
Happy的楠姐 2021-01-01 12:38

I wanted to generate code coverage reports on my JUnit tests in my android project so I added the JaCoCo gradle plugin. This is my project level build.gradle fi

5条回答
  •  一生所求
    2021-01-01 13:06

    The accepted answer is a bit dated. Here is a similar fix we just implemented. In the module (i.e. app) build.gradle add:

    apply plugin: 'jacoco'
    
    tasks.withType(Test) {
        jacoco.includeNoLocationClasses = true
    }
    

    This does require JaCoCo 7.6+, but you are likely using it already.

    Notes for Studio:

    1. This only fixes the CLI. If you run coverage from Studio using JaCoCo, the Robolectric coverage is still not reported. The default IntelliJ Coverage Runner seems to work fine.
    2. The test were crashing intermittently in Studio unless I added -noverify to the Android JUnit -> VM Options

提交回复
热议问题