【问题标题】:Execute Instrumented Test for an Android Library with Firebase Test Lab?使用 Firebase 测试实验室为 Android 库执行检测测试?
【发布时间】:2020-01-20 16:50:22
【问题描述】:

我正在研究 CircleCI,我正在尝试使用 Firebase 测试实验室为 Android 库执行仪器测试(因为 CircleCI 不支持 Android 虚拟设备)。

我的 Instrumented Test 在 Android Studio 下就像一个魅力,但在 Firebase 测试实验室下执行它时,它却在挣扎!

事实上,主要的问题是,当我编译我的库时,我的输出中没有 APK 文件,而是一个 AAR 文件!

$ ./gradlew assembleDebug
$ ./gradlew assembleDebugAndroidTest

那么您对使用 Firebase 测试实验室为 Android 库运行 Instrumented Test 有什么建议吗?

这里我的命令不起作用(由 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

【问题讨论】:

  • 您仍然需要构建一个 APK 进行测试,即使您构建的是库而不是应用程序。
  • 嗨@DougStevenson,谢谢!您的解决方法有效!

标签: android firebase circleci fastlane firebase-test-lab


【解决方案1】:

感谢@DougStevenson,我只是在我的库项目中添加了一个子项目文件夹testlab/,其中包含一个非常简单的Android App,它实现了我的库。 build.gradle 文件如下:

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'])
}

然后在我的 fastlane/Fastfile 文件中,我在运行我的仪器测试之前编译“测试 APK”:

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

【讨论】:

  • 您是否必须将“yourLibrary/src/androidTest”下的所有测试移动到“testlab/src/androidTest”?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多