mardi 5 juin 2018

Code Coverage in Android Studio with JUnit

I'm trying to get code coverage metrics for my project in Android Studio.

In my App I have a class in the test package named RouterTest that contains a lot of tests. All tests run fine and as expected, but when I try to get some code coverage metrics, it says it can't find any tests.

I've been trying to find tutorials and answers to my problem, but I didn't find an answer so far.

I have this in my build.gradle (Module: app)

android {
    ...
    buildTypes {
        ... 
        debug {
            ...
            testCoverageEnabled true
        }
    }
}


dependencies {
    ...
    // =======================
    //          Tests
    // =======================
    testImplementation 'junit:junit:4.12' // Required -- JUnit 4 framework
    testImplementation 'org.mockito:mockito-core:2.11.0' // Optional -- Mockito framework
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

}

My RouterTest.class is annotated to run with JUnit4 like so:

@RunWith(AndroidJUnit4.class)
public class RouterTest extends ApplicationTestCase<Application> {

    ... Lots of tests

}

My Configuration: My configuration

And the result is always a very disappointing "No tests were found".

What am I missing?

Thank you for your help.

Aucun commentaire:

Enregistrer un commentaire