Set up project for Android Test

In order to use Android Test, you must modify your app project's classpath dependencies within your development environment, as shown in the following steps:

  1. Open the build.gradle file for your app.
  2. In the repositories section, add Google's Maven repository. To do so, add a maven section with the "https://maven.google.com" endpoint. For example:

    allprojects {
        repositories {
            jcenter()
            maven {
                url "https://maven.google.com"
            }
        }
    }
  3. For each Android Test package you want to use, add its package name to the dependencies section. For example, to add the espresso-core package, add the following lines:

    dependencies {
        ...
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    }

    Caution: Using dynamic dependencies (for example, espresso-core:3.0.0+) can cause unexpected version updates and regression incompatibilities. We recommend that you explicitly specify a particular version number (for example, espresso-core:3.0.0).

List of Android Test dependencies

Android Test includes many dependencies. As discussed in Adding Gradle dependencies from a Maven repository, you can add these dependencies to your development environment by adding each dependency within your module-level build.gradle file.

The following dependencies are available in Android Test:

dependencies {
  // AndroidJUnitRunner and JUnit Rules
  androidTestImplementation 'com.android.support.test:runner:1.0.2'
  androidTestImplementation 'com.android.support.test:rules:1.0.2'

  // Espresso dependencies
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
  androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
  androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
  androidTestImplementation 'com.android.support.test.espresso:espresso-accessibility:3.0.2'
  androidTestImplementation 'com.android.support.test.espresso:espresso-web:3.0.2'
  androidTestImplementation 'com.android.support.test.espresso.idling:idling-concurrent:3.0.2'

  // The following Espresso dependency can be either "implementation"
  // or "androidTestImplementation", depending on whether you want the
  // dependency to appear on your APK's compile classpath or the test APK
  // classpath.
  androidTestImplementation 'com.android.support.test.espresso:espresso-idling-resource:3.0.2'
}