ShadowFlame
ShadowFlame

Reputation: 3258

android studio robolectric test no coverage

First off, I know that this question appears to be a duplicate. However, none of the other questions are recent enough to still work. I've tried it.

The problem is as follows:

when using the internal "Run with coverage" functionality of Android Studio with jacoco as coverage generator, I don't get any coverage for tests with RobolectricRunner.

my testOptions part in my app level build.gradle:

testOptions {
        reportDir = "$project.buildDir/test-results"
        unitTests.returnDefaultValues = true
        unitTests {
            includeAndroidResources = true
        }
    }

I'm using

AS 3.3
Gradle 4.10
classpath 'com.android.tools.build:gradle:3.2.0'
testImplementation "org.robolectric:robolectric:4.0.1"
compileSdkVersion 25 //this is a hard dependecy, can't change this one

I've tried quite a few things to even be able to run my tests with coverage if they were robolectric at all, but it remains at 0%.

At the moment I don't have any specific references to jacoco, so I would think that I'm using the default Android Studio Version. If anyone can point me as to how to find that version, I'd be grateful.

If you need any aditional information, i will gladly provide it.

Upvotes: 3

Views: 2093

Answers (1)

underwood
underwood

Reputation: 309

I think you should try to add specific configuration of jacoco in your test unit , so the final code is here :


      testOptions {
        reportDir = "$project.buildDir/test-results"
        unitTests.all {
            jacoco {
                includeNoLocationClasses = true
                jvmArgs '-noverify'
            }
        }
    }

Upvotes: 0

Related Questions