lightbulb_outline Help shape the future of the Google Play Console, Android Studio, and Firebase. Start survey

Legacy testing libraries

Android P has reorganized the JUnit-based classes into three libraries: android.test.base, android.test.runner, and android.test.mock. For details about which classes appear in each library, see the Class reorganization details section.

This guide shows the changes that you need to make to your app so that your tests still build and run properly.

Gradle build file changes

To continue building tests that rely on former framework packages, add the following lines to your app's build.gradle file:

app/build.gradle

android {
    ...

    // Required if using classes in android.test.runner
    useLibrary 'android.test.runner'

    // Required if using classes in android.test.base
    useLibrary 'android.test.base'

    // Required if using classes in android.test.mock
    useLibrary 'android.test.mock'
}

Recommended manifest file changes

To run tests that rely on former framework test classes, you should add the necessary <uses-library> elements to your test app's manifest.

If you add tests that depend on the android.test.runner library, you should add the following element to your app's manifest:

<!-- You don't need to include android:required="false" if your app's
     minSdkVersion is 28. -->
<uses-library android:name="android.test.runner"
              android:required="false" />

Considerations when targeting only Android P

The guidance in this section applies only if you target Android P and the minimum SDK version for your app is set to Android P.

The android.test.runner library implicitly depends on the android.test.base and android.test.mock libraries. If your app only uses classes from android.test.base or android.test.mock, you can include the libraries by themselves:

<!-- For both of these declarations, you don't need to include
     android:required="false" if your app's minSdkVersion is 28. -->
<uses-library android:name="android.test.base"
              android:required="false" />
<uses-library android:name="android.test.mock"
              android:required="false" />

Class reorganization details

The following lists show the classes that are contained in each library.

android.test.base

This library consists of the following non-deprecated classes, each of which is in the junit.framework package:

The library also consists of the following deprecated classes:

android.test package

android.test.suitebuilder.annotation package

com.android.internal.util package

android.test.runner

This library consists of the following non-deprecated classes:

android.test package

junit.runner package

The library also consists of the following deprecated classes:

android.test package

android.test.suitebuilder package

android.test.mock

This library consists of the following non-deprecated classes, each of which is in the android.test.mock package:

The library also consists of the following deprecated classes, each of which is also in the android.test.mock package: