Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Gradle androidTest vs instrumentTest

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?

like image 310
SBerg413 Avatar asked Mar 02 '15 17:03

SBerg413


People also ask

When should you use androidTest directory to store your test classes?

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+).

What is the difference between unit tests and instrumented tests?

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.

Which of the following are differences between local and instrumented tests in Android?

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.


1 Answers

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.

like image 93
CommonsWare Avatar answered Oct 14 '22 04:10

CommonsWare