I'm adding unit tests to my existing Android Studio project and I'm a bit confused with the setup. Particularly, the androidTest vs instrumentTest flags within the gradle script. Can someone explain the different between these 2 sections and what exactly they target vs the other.
My project was migrated from an Eclipse project, so it does not have the default gradle structure. Here's what I've been playing around with:
androidTest {
setRoot('tests')
java.srcDirs = ['tests/src']
}
instrumentTest {
setRoot('tests')
java.srcDirs = ['tests/src']
manifest.srcFile file('tests/AndroidManifest.xml')
}
Is there any reason to have both?
When should you use the androidTest directory to store your test classes? when the tests consist only of unit tests. when the number of tests to run is large(500+).
Unit tests are useful for testing code which doesn't call the Android API, and the Android instrumentation tests are rather integration tests to test Android API specific elements or GUI components.
There are Local and Instrumentation test cases. The main difference between these tests is that the "local" test can be executed on JVM (Java Virtual Machine) and a specific version of JVM with Android dependencies, delivered as part of the Robolectric library, which allows us to test Android-specific code.
Is there any reason to have both?
No, because they are the same thing, as instrumentTest
was renamed androidTest
in version 0.9.0 of the Gradle for Android plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With