Skip to main content

Running instrumented tests for Android apps

Instrumented tests run on Android devices, whether physical or emulated. On Bitrise, you can run instrumented tests using the adb tool. To run your instrumented tests, you need two Steps:

  • The Android Build for UI testing Step builds both an APK and a test APK. For example, MyappDebug.apk and MyAppDebugAndroidTest.apk. The Step stores the path to these APKs in two output Environment Variables: BITRISE_APK_PATH and BITRISE_TEST_APK_PATH. You can use these Env Vars to access the APKs in subsequent Steps in the same Workflow.

  • The Android Instrumented Test Step runs the instrumented tests using the APKs built in the previous Step.

To run instrumented tests for Android:

  1. Add the Android Build for UI testing Step to your Workflow.

  2. Make sure the Project location input points to the root directory of your Android app.

  3. Set the module and the variant you want to build in the Module and the Variant input.

    You can check the available modules and variants of your project in the Project window in Android Studio.

  4. In the Options input group, you can set the location for the generated APK files.

    The input takes a file pattern as a value. The default value is */build/outputs/apk/*.apk.

  5. Optionally, you can pass additional Gradle arguments to the build task in the Additional Gradle Arguments input.

  6. Add the Android Instrumented Test Step to the Workflow, at some point after the Android Build for UI testing Step.

  7. Make sure that the Main APK path and the Test APK path inputs point to the correct location.

    By default, the values of the two inputs are the BITRISE_APK_PATH and the BITRISE_TEST_APK_PATH Environment Variables, respectively. These variables are exported by the Android Build for UI testing Step. As such, in the vast majority of cases, you don't have to modify the value of these inputs.

  8. In the Test runner class input, specify the test runner you wish to use.

    The default runner is the AndroidJUnitRunner class.

  9. Optionally, you can pass additional options to the test runner with the Additional testing options input.

    With this input, you issue commands to the activity manager tool of the adb shell. For more information about the commands you can issue, see the official documentation for adb.

Run your tests and view their results in the build logs.