You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

Firebase Test Lab与CircleCI集成失败求助:配置后未执行测试

分析你的CircleCI + Firebase Test Lab配置问题

看起来你的配置里有几个关键遗漏点,导致测试没有在Firebase Test Lab正常执行,我帮你梳理并给出修复方案:

1. 未从Build Job拉取生成的APK文件

你的build job已经通过persist_to_workspace保存了编译好的APK,但test_instrumented job没有挂载这个工作区——两个job运行在不同的容器里,gcloud容器根本找不到build阶段生成的APK文件,自然无法启动测试。

你需要在test_instrumented的steps最开头添加挂载工作区的步骤:

test_instrumented:
  <<: *gcloud_config
  steps:
    - attach_workspace:
        at: ~/github-jobs  # 必须和build job的working_directory完全一致
    - *export_gcloud_key
    - *decode_gcloud_key
    # 后续步骤保持不变

2. 工作目录与文件路径的一致性问题

注意test_instrumented里的gcloud命令要使用完整的工作区路径来指向APK,否则会找不到文件。比如把原命令里的app/build/outputs/apk/...改成~/github-jobs/app/build/outputs/apk/...

3. 服务账号权限验证

请确认你的服务账号firebase-circleci@dazzling-fire-5515.iam.gserviceaccount.com拥有Firebase Test Lab Editor或更高权限(比如Project Editor)。如果权限不足,gcloud命令会静默失败或抛出权限错误,你可以去CircleCI的job日志里查看具体报错信息。

4. 可选:添加调试步骤排查问题

如果还是无法执行,建议在test_instrumented里添加一个验证文件存在的步骤,确认APK是否成功拉取:

- run:
    name: Verify APK files exist
    command: ls -la ~/github-jobs/app/build/outputs/apk/debug/ ~/github-jobs/app/build/outputs/apk/androidTest/debug/

修改后的完整test_instrumented Job示例

test_instrumented:
  <<: *gcloud_config
  steps:
    - attach_workspace:
        at: ~/github-jobs
    - *export_gcloud_key
    - *decode_gcloud_key
    - run:
        name: Verify APK files exist
        command: ls -la ~/github-jobs/app/build/outputs/apk/debug/ ~/github-jobs/app/build/outputs/apk/androidTest/debug/
    - run:
        name: Set Google Cloud target project
        command: gcloud config set project dazzling-fire-5515
    - run:
        name: Authenticate with Google Cloud
        command: gcloud auth activate-service-account firebase-circleci@dazzling-fire-5515.iam.gserviceaccount.com --key-file ${HOME}/client-secret.json
    - run:
        name: Run instrumented test on Firebase Test Lab
        command: gcloud firebase test android run --type instrumentation --app ~/github-jobs/app/build/outputs/apk/debug/app-debug.apk --test ~/github-jobs/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk --device model=Nexus5X,version=26,locale=en_US,orientation=portrait --environment-variables coverage=true,coverageFile=/sdcard/tmp/code-coverage/connected/coverage.ec --directories-to-pull=/sdcard/tmp --timeout 20m
    - run:
        name: Create directory to store test results
        command: mkdir ~/github-jobs/firebase
    - run:
        name: Download instrumented test results from Firebase Test Lab
        command: gsutil -m cp -r -U "`gsutil ls gs://test-lab-3udbiqpdyp0d0-miwcp7d69v80m | tail -1`*" ~/github-jobs/firebase/
    - persist_to_workspace:
        root: ~/github-jobs
        paths:
          - firebase
    - store_artifacts:
        path: ~/github-jobs/firebase/
        destination: /firebase/

最后:添加Workflow串联Jobs

别忘了在配置末尾添加Workflow,让test_instrumentedbuild成功后再执行:

workflows:
  version: 2
  build_and_test:
    jobs:
      - build
      - test_instrumented:
          requires:
            - build

内容的提问来源于stack exchange,提问作者N Sharma

火山引擎 最新活动