Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute Instrumented Test for an Android Library with Firebase Test Lab?

I'm working on CircleCI, and I'm trying to execute Instrumented Tests for an Android Library with Firebase Test Lab (because Android Virtual Devices are not supported by CircleCI).

My Instrumented Test works like a charm under Android Studio, but when it comes to execute it's under Firebase Test Lab, it struggling!

In fact the main problem is that when I'm compiling my library, I have no APK file in output, but an AAR file instead!

$ ./gradlew assembleDebug
$ ./gradlew assembleDebugAndroidTest

So do you have any suggestion to run Instrumented Test for an Android library with Firebase Test Lab?

Here my commands which doesn't work (generated by fastlane):

$  gcloud firebase test android run \
   --type instrumentation \ 
   --app lib/build/outputs/apk/androidTest/debug/lib-debug-androidTest.apk \
   --test lib/build/outputs/apk/androidTest/debug/lib-debug-androidTest.apk \
   --device model=walleye,version=28,locale=en_US,orientation=portrait \
   --timeout 30m
$ gcloud firebase test android run \
  --type instrumentation \
  --test lib/build/outputs/apk/androidTest/debug/lib-debug-androidTest.apk \
  --device model=walleye,version=28,locale=en_US,orientation=portrait \
  --timeout 30m
like image 346
Christopher Avatar asked Jan 20 '20 16:01

Christopher


People also ask

What is instrumented test Android?

Instrumented tests are tests that run on physical devices and emulators, and they can take advantage of the Android framework APIs and supporting APIs, such as AndroidX Test.

How do you use test lab in firebase?

On the Firebase console navigation bar, click Test Lab, and then click Get Started -> Run a Robo test. Click Browse, browse to your app APK, and then click Continue. Define your test matrix by selecting which devices, Android API levels, screen orientations and locales you want to test your app against.

Is Firebase Test Lab free?

$5 per hour for each physical device. $1 per hour for each virtual device.


1 Answers

Thanks to @DougStevenson, I just add a sub-project folder testlab/ in my library project, with a very simple Android App, which implement my library. The build.gradle file below:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 29
    buildToolsVersion "29.0.0"
    defaultConfig {
        applicationId "com.soclip.library.analytics"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
    }
}
dependencies {
    // Include the Android library (aar file)
    implementation fileTree(dir: '../../lib/build/outputs/aar/', include: ['*.aar'])
}

Then in my fastlane/Fastfile file, I compile the "test APK" before run my Instrumented Tests:

default_platform(:android)
platform :android do

  desc "Assemble Library"
    lane :assemble_library do
      gradle(task: "assembleDebug")
  end

  desc "Assemble App (for Firebase Test Lab)"
    lane :assemble_application do
      gradle(task: "assembleDebug", project_dir: "testlab/")
  end

  desc "Assemble Android Test"
    lane :assemble_test_application do
      gradle(task: "assembleDebugAndroidTest")
  end

  desc "Assemble Build and Test Application"
  lane :assemble do
    assemble_library
    assemble_application
    assemble_test_application
  end

  desc "Run instrumentation tests in Firebase Test Lab"
  lane :instrumentation_tests_testlab do
    assemble
    run_tests_firebase_testlab(
      project_id: "my-firebase-project-id",
      app_apk: "testlab/app/build/outputs/apk/debug/app-debug.apk",
      android_test_apk: "lib/build/outputs/apk/androidTest/debug/lib-debug-androidTest.apk",
      devices: [
        {
          model: "walleye",
          version: "28"
        }
      ],
      delete_firebase_files: true)
  end

end

like image 80
Christopher Avatar answered Sep 21 '22 20:09

Christopher