> 九號工具站
返回列表

Firebase Test Lab 完整指南 — Android QA 免費神器(Robo / Instrumentation / Game Loop)

Firebase Test Lab 完整指南。3 種測試類型、跨真機矩陣、Robo auto-explorer、CI 整合(gcloud + GitHub Actions)、vs BrowserStack 對比、iOS 限制、成本控制、常見坑。

QA firebase-test-lab android mobile gcloud robo-test
· 最後更新 2026-06-18 · 最後審閱 2026-08-30

💡 本文原刊於 qa.9niche.com,2026-08 併入 9niche.com 懶人包,內容照原文完整搬遷。

1. 前言

「我們 app 只在 Pixel 上測、Samsung Galaxy S 上就爆」 — 跨真機是 Android QA 永恆痛點。Firebase Test Lab(FTL)是 Google 維護的真機池、免費起跳、跑 100+ 設備矩陣。這篇給你完整 setup + workflow。

2. 為什麼 FTL 是 Android 首選

flowchart LR Choice{選 device farm?} --> FTL[Firebase Test Lab] Choice --> BS[BrowserStack] Choice --> SL[Sauce Labs] Choice --> AWS[AWS Device Farm] FTL --> F1[免費 5h/day virtual] FTL --> F2[1h/day physical] FTL --> F3[Pixel / Samsung / 摩托羅拉] FTL --> F4[Crashlytics 串連] FTL --> F5[Robo Test 自動爬] FTL --> F6[Google Play 推薦工具] BS --> B1[$39/月起] BS --> B2[iOS 強] style FTL fill:#10b981,color:#fff style F1 fill:#10b981,color:#fff

3. 3 種測試類型

1. Instrumentation Test(Espresso)

@RunWith(AndroidJUnit4::class)
class LoginTest {
    @get:Rule
    val rule = ActivityScenarioRule(LoginActivity::class.java)

    @Test
    fun loginWithValidCredentials() {
        onView(withId(R.id.email)).perform(typeText("[email protected]"))
        onView(withId(R.id.password)).perform(typeText("Test@123"))
        onView(withId(R.id.loginBtn)).perform(click())
        onView(withId(R.id.welcomeText)).check(matches(isDisplayed()))
    }
}

Build APK + 上傳:

./gradlew assembleDebug assembleAndroidTest

gcloud firebase test android run \
  --type instrumentation \
  --app app/build/outputs/apk/debug/app-debug.apk \
  --test app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk \
  --device model=Pixel7,version=33 \
  --device model=SamsungGalaxyS22,version=33 \
  --device model=motox4,version=27

2. Robo Test — 不寫 code 神器

gcloud firebase test android run \
  --type robo \
  --app app/build/outputs/apk/debug/app-debug.apk \
  --device model=Pixel7,version=33 \
  --timeout 5m \
  --robo-directives [email protected],loginPassword=Test@123

會發生什麼

  1. FTL 安裝 APK
  2. AI 自動點擊 / 滑動 / 輸入、像猴子一樣探索
  3. 5 分鐘內試圖覆蓋每個 screen
  4. 抓 crash、ANR、UI freeze
  5. 產出影片 + 截圖 + activity graph

5 分鐘設定 = 一週手動測試覆蓋

3. Game Loop Test

遊戲開發者用、app 跑「demo mode」、FTL 評估 FPS / crash。本文不深入。

flowchart TD FTL[FTL 測試] --> T1[Instrumentation Test] FTL --> T2[Robo Test] FTL --> T3[Game Loop Test] T1 --> T1d["寫 Espresso / UI Automator<br>完整控制、需 dev 配合"] T2 --> T2d["不寫 code<br>AI 自動點擊探索<br>抓 crash + 截圖"] T3 --> T3d["遊戲專用<br>跑遊戲內 looping mode"] style T1 fill:#06b6d4,color:#fff style T2 fill:#a855f7,color:#fff style T3 fill:#f59e0b,color:#fff

4. 跨設備矩陣

列設備池

gcloud firebase test android models list
# 列出所有可用設備

Matrix run 範例

gcloud firebase test android run \
  --type instrumentation \
  --app app-debug.apk \
  --test app-debug-androidTest.apk \
  --device model=Pixel7,version=33,locale=en,orientation=portrait \
  --device model=SamsungGalaxyS22,version=33,locale=zh_TW,orientation=portrait \
  --device model=Pixel3,version=28,locale=ja,orientation=landscape \
  --num-flaky-test-attempts 1
flowchart TD Matrix[Device Matrix] --> Real[Physical 真機] Matrix --> Virt[Virtual emulator] Real --> R1[Pixel 7/8/9] Real --> R2[Samsung Galaxy S22/S23] Real --> R3[OnePlus / Motorola / Nokia] Real --> R4["100+ 機種"] Virt --> V1[Pixel virtual 多版本] Virt --> V2[更便宜 / 更快] Virt --> V3["跨 API 21-34"] style Real fill:#10b981,color:#fff style Virt fill:#06b6d4,color:#fff

5. CI 整合 — GitHub Actions

name: Android E2E (Firebase Test Lab)

on:
  pull_request:
  push:
    branches: [main]

jobs:
  ftl-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '17'

      - name: Build APK + Test APK
        run: |
          ./gradlew assembleDebug assembleAndroidTest

      - name: Auth Google Cloud
        uses: google-github-actions/auth@v2
        with:
          credentials_json: ${{ secrets.GCP_SA_KEY }}

      - name: Setup gcloud
        uses: google-github-actions/setup-gcloud@v2
        with:
          project_id: my-firebase-project

      - name: Run on Firebase Test Lab
        run: |
          gcloud firebase test android run \
            --type instrumentation \
            --app app/build/outputs/apk/debug/app-debug.apk \
            --test app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk \
            --device model=Pixel7,version=33 \
            --device model=SamsungGalaxyS22,version=33 \
            --results-bucket my-test-results \
            --timeout 15m \
            --no-record-video

Service Account 設置

  1. Google Cloud Console → IAM → Service Accounts
  2. 建 SA、grant Firebase Test Lab Admin + Firebase Analytics Viewer
  3. 下載 JSON key → 存 GitHub Secrets GCP_SA_KEY

6. 結果分析

flowchart LR Run[Test Run] --> Results[Results in Firebase Console] Results --> R1["✓ Pass / ✗ Fail per device"] Results --> R2[影片 replay] Results --> R3[Screenshot at fail step] Results --> R4[Logcat 完整 log] Results --> R5[Performance metrics<br>CPU / Memory / Network] Results --> R6[ANR detection] Results --> R7[Crash stack trace] Results --> S[Cloud Storage bucket] S --> Download[下載 raw artifact] style Results fill:#a855f7,color:#fff

7. 跟 Crashlytics 串連

FTL 抓到 crash → 自動上傳 Crashlytics → 跟 production crash 同 dashboard 看。

// Initialize Crashlytics in test mode
class TestApp : Application() {
    override fun onCreate() {
        super.onCreate()
        if (BuildConfig.DEBUG) {
            FirebaseCrashlytics.getInstance().setCustomKey("env", "ftl")
        }
    }
}

Production crash + FTL crash 都看得到趨勢

8. 跟 Detox 整合

# 1. Local 跑 Detox
detox build -c android.emu.debug

# 2. 上傳到 FTL 跑跨設備
gcloud firebase test android run \
  --type instrumentation \
  --app android/app/build/outputs/apk/debug/app-debug.apk \
  --test android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk \
  --device model=Pixel7,version=33 \
  --device model=SamsungGalaxyS22,version=33

Local Detox 快 debug + FTL 跨真機驗證

9. iOS 支援 — 警告

✗ iOS 設備少(< 20 個)
✗ 大多舊版(iOS 16-17)
✗ 沒 iPad Pro 最新版
✗ 只支援 XCUITest(不支援 Detox iOS)

iOS 為主 → BrowserStack

10. 成本控制

PlanVirtualPhysical月費
Spark (free)5 hr/day1 hr/day$0
Blaze (pay-as-you-go)$1/hr$5/hr按用量

Cost 計算

Matrix run: 5 設備 × 10 分鐘 = 50 device-minutes ≈ 0.83 hr
Daily cost: 0.83 × $5 = $4.15

每天跑 4 次 (PR + nightly):
$4.15 × 4 = $16.60/day
$500/month

省錢策略

  • 80% virtual + 20% physical
  • 只在 main / release 跑 full matrix
  • PR 只跑 Pixel + Samsung 兩個
  • Robo Test 替代部分 Instrumentation

11. Robo Test 進階

Robo Directives — 引導測試

gcloud firebase test android run \
  --type robo \
  --app app-debug.apk \
  --device model=Pixel7,version=33 \
  --robo-directives \
      "[email protected],loginPassword=Test@123,IGNORE_skipBtn=,CLICK_loginBtn="
  • [email protected] — text 欄位自動填
  • IGNORE_skipBtn= — 跳過某按鈕
  • CLICK_loginBtn= — 強制點某按鈕

Robo Script — 錄製手動操作

# 1. 錄製
gcloud firebase test android run --type robo \
  --robo-script myscript.json

Android Studio 內可以「錄製」操作 → 存成 script → 上傳跑。

12. 反模式

flowchart TD Anti[FTL 反模式] --> A1["每 PR 跑 30 個設備"] Anti --> A2["全用 physical、燒錢"] Anti --> A3["不看 Robo Test 結果"] Anti --> A4["不設 timeout"] Anti --> A5["不串 Crashlytics"] Anti --> A6["iOS 硬要用 FTL"] Anti --> A7["不存 result bucket"] style A1 fill:#ef4444,color:#fff style A2 fill:#ef4444,color:#fff style A3 fill:#ef4444,color:#fff style A4 fill:#ef4444,color:#fff style A5 fill:#ef4444,color:#fff style A6 fill:#ef4444,color:#fff style A7 fill:#ef4444,color:#fff

13. 跟 BrowserStack / Sauce Labs 對比

維度Firebase Test LabBrowserStackSauce Labs
Android 設備100+ 真機100+100+
iOS 設備< 20、老100+ 含最新100+
起跳價免費 5h/day$39/month企業向
Robo Test✓ 內建
Crash 整合CrashlyticsManualManual
CI 體驗gcloud CLIREST APIAPI
Game testingGame Loop
真機 vs 雲端真實設備真實設備真實設備

14. 給 Android QA 的 5 句

  1. Android 為主、FTL 是首選
  2. Robo Test 是 baseline 探索神器、必用
  3. 80% virtual + 20% physical 省錢
  4. CI 串 gcloud CLI、SA key 用 Secrets
  5. iOS 為主請另尋 BrowserStack

15. 最後

Firebase Test Lab 是 Android QA 最被低估的免費神器。Robo Test 一鍵跨 5 個設備、5 分鐘抓 crash、配合 Crashlytics + Crashlytics + Performance Monitoring 串成完整 Android quality 體系。從每天免費跑 5 hr 起步、半年後你會問「為什麼以前沒早點用」。

延伸:

ℹ️

一般聲明

本站提供之資訊僅供參考,不保證其完整性與正確性。使用者應自行判斷資訊之適用性。

意見反饋