(Android) Run tests using the emulator

Description

Run any kind of tests (unit, instrumentation) on a local emulator instance.

Instructions

  1. Add an AVD Manager Step. To customize the emulator, see the Step configuration.

  2. Add a Wait for Android emulator Step.

  3. Add a Gradle Runner Step. Set the input variables:

    • Gradle task to run: for example, connectedDebugAndroidTest.

    • gradlew file path: for example, ./gradlew.

  4. Add an Export test results to Test Reports add-on Step with the following inputs:

    • The name of the testEmulator tests.

    • Test result base path$BITRISE_SOURCE_DIR/app/build/outputs/androidTest-results.

      You might want to adjust the path based on the module name(s) in your project.

    • Test result search pattern*.xml.

  5. Add a Deploy to Bitrise.io Step that makes the test results available in the Test Reports add-on.

bitrise.yml

- avd-manager@1: {}
- wait-for-android-emulator@1:
- gradle-runner@2:
    inputs:
    - gradlew_path: ./gradlew
    - gradle_task: connectedDebugAndroidTest
- custom-test-results-export@0:
    inputs:
    - search_pattern: "*.xml"
    - base_path: $BITRISE_SOURCE_DIR/app/build/outputs/androidTest-results
    - test_name: Emulator tests
- deploy-to-bitrise-io@2: