Execute Instrumented Test for an Android Library with Firebase Test Lab?
Asked Answered
S

1

6

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
Succoth answered 20/1, 2020 at 16:50 Comment(2)
You will still need to build an APK to test with, even if you're building a library instead of an app.Lusitania
Hi @DougStevenson, thanks! Your workaround works !Succoth
S
3

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

Succoth answered 20/1, 2020 at 19:43 Comment(1)
Did you have to move all your tests under "yourLibrary/src/androidTest" to "testlab/src/androidTest" ?Tawny

© 2022 - 2024 — McMap. All rights reserved.