Deploying Android Apps Using GitHub Actions

May 4 2023 · Kotlin 1.7.21, Android 13, Android Studio Electric Eel

Part 1: Automate Releases with GitHub Actions

03. Run Unit & Instrumented Tests

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 02. Create a GitHub Workflow Next episode: 04. Generate a Signed Build

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

There are two ways you can run tests in your projects:

Run Unit Tests

To run the unit tests for the debug variant of your app, run the following command:

./gradlew testDebugUnitTest

Run Instrumented Tests

To run the instrumented tests, you need to first have a device or emulator connected. Then, run the following command to execute the tests for the debug variant of your app:

./gradlew connectedDebugAndroidTest

Add Jobs to Workflow

Now that you know how to run the tests from the command line, it’s time to add the jobs to the workflow.

jobs:
  unit_tests:
    runs-on: [ubuntu-latest]
    steps:
      - uses: actions/checkout@v3
      - name: set up JDK
        uses: actions/setup-java@v3
        with:
          distribution: 'zulu'
          java-version: 11
      - name: Unit tests
        run: ./gradlew testDebugUnitTest
  android_tests:
    runs-on: [ macos-12 ]
    steps:
      - uses: actions/checkout@v3
      - name: set up JDK
        uses: actions/setup-java@v3
        with:
          distribution: 'zulu'
          java-version: 11
      - name: Instrumented Tests
        uses: reactivecircus/android-emulator-runner@v2
        with:
          api-level: 29
          script: ./gradlew connectedDebugAndroidTest