Confused about testCompile and androidTestCompile in Android Gradle

前端 未结 4 881
后悔当初
后悔当初 2020-11-30 20:53

I\'m new to testing world and even more to Android testing world. While doing research on Robolectric that aids with tests on android one thing confuses me the most. Sometim

4条回答
  •  难免孤独
    2020-11-30 21:47

    //unit testing

    testCompile 'junit:junit:4.12'
    

    The above code is a dependency of JUnit 4 in build.gradle file in android studio. You see that it has testCompile, beacuse JUnit runs on JVM and does not require a device or emulator to run. That also means that JUnit tests will not require the application context to run and if they require we would need to "MOCK" them.

    //Insturmented Unit Testing

    androidTestCompile('com.android.support.test:runner:0.5', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
    

    Now we see androidTestCompile here, because this time we intend to use the device or emulator for tests, that is Instrumentation testing. For beter clarification I would suggest to read from developer.android.com

提交回复
热议问题