Confused about testCompile and androidTestCompile in Android Gradle

Lucas picture Lucas · Mar 12, 2015 · Viewed 23k times · Source

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. Sometimes on the web I see people using testCompile keyword in dependencies of the gradle build script when referencing Robolectric while others use androidTestCompile. Certainly both can't be valid?

Can somebody explain the difference between the both and which of these should be the one used when using Robolectric?

Answer

Mark Vieira picture Mark Vieira · Mar 13, 2015

Simply testCompile is the configuration for unit tests (those located in src/test) and androidTestCompile is used for the test api (that located in src/androidTest). Since you are intending to write unit tests, you should use testCompile.

Update: The main distinction between the two is the test sourceset runs in a regular Java JVM, whereas the androidTest sourceset tests run on an Android device (or an emulator).