If you’ve recently started using the AndroidX libraries for your Android automated UI tests (also known as Instrumented Tests or Espresso Tests), you may find yourself getting frustrated when accessing some of the common testing classes.

As of this writing, a project generated with the current version of Android Studio that uses AndroidX does not include all of the dependencies required to use familiar testing classes like AndroidJUnit4, ActivityTestRule and others.

To remedy this issue, you want to be sure to have androidTestImplementation depency entries for the following libraries:

  • androidx.test:core
  • androidx.test:rules
  • androidx.test.ext:junit
  • androidx.test:runner
  • androidx.test.espresso:espresso-core

Once you have those in place, you’ll be good-to-go!

For reference, the following is the dependency section from a project I recently created that relies on AndroidX rather than the Android Support Libraries:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:core:1.2.0'
    androidTestImplementation 'androidx.test:rules:1.2.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

Posted by hedgehogjim

30+ years as a professional software dev, 17+ years developing mobile solutions, Pluralsight Author, Founder JWHH, LLC

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s