QA Testing (Android)
Android testing automation with Espresso, UIAutomator, and Compose Testing.
Core References: Android Testing Docs, Espresso, Compose Testing
Quick Reference
| Task |
Command |
| List emulators |
emulator -list-avds |
| Start emulator |
emulator @<avd_name> |
| List devices |
adb devices |
| Install APK |
adb install -r <path-to-apk> |
| Run unit tests |
./gradlew test |
| Run instrumented tests (connected) |
./gradlew connectedAndroidTest |
| Run instrumented tests (GMD) |
./gradlew <device><variant>AndroidTest |
| List GMD tasks |
`./gradlew tasks --all |
| Clear app data |
adb shell pm clear <applicationId> |
Quick Start (2026 Defaults)
- Prefer Gradle Managed Devices (GMD) + ATD images for CI; use
connectedAndroidTest for local ad-hoc runs.
- Enable test isolation via AndroidX Test Orchestrator for instrumented tests.
- Disable animations via Gradle
testOptions (preferred) instead of per-runner ADB steps.
- Keep selectors stable:
withId() (Views), testTag (Compose), resource-id/content-desc (UIAutomator).
Recommended Gradle defaults for stable instrumented tests (version catalog names vary by project):
android {
testOptions {
animationsDisabled = true
execution = "ANDROIDX_TEST_ORCHESTRATOR"
}
}
dependencies {
androidTestUtil(libs.androidx.test.orchestrator)
}
When to Use
- Debug or stabilize flaky Android UI tests
- Add Espresso tests for View-based UIs
- Add Compose UI tests for composables
- Add UIAutomator tests for system UI or cross-app flows
- Set up an Android test gate in CI
Inputs to Gather
- UI stack: Views, Compose, or mixed
- Test layer: unit, Robolectric, instrumented UI, UIAutomator/system
- CI target: PR gate vs nightly vs release; emulator vs device farm
- Device matrix: min/target API, form factors, locales (if relevant)
- Flake symptoms: timeouts, missing nodes, idling/sync, device-only issues
- App seams: DI hooks for fakes, feature flags, test accounts/test data
Testing Layers
| Layer |
Framework |
Scope |
| Unit |
JUnit + Mockito |
JVM, no Android |
| Unit (Android) |
Robolectric |
JVM, simulated |
| UI (Views) |
Espresso |
Instrumented |
| UI (Compose) |
Compose Testing |
Instrumented |
| System |
UIAutomator |
Cross-app |
Core Principles (Stability)
Device Matrix
- Default: emulators for PR gates; real devices for release
- Cover: min supported API level, target API level, plus tablet/foldable if supported
Flake Control
- Prefer Gradle
testOptions { animationsDisabled = true } for instrumented tests
- Use AndroidX Test Orchestrator to isolate state and recover from crashes
- Use IdlingResources / Compose idling +
waitUntil instead of sleeps
- Mock network with
MockWebServer (or your DI fake) and avoid live backends
- Reset app state per test (test account/data, storage, feature flags)
Writing Tests
- Espresso (Views): open
references/espresso-patterns.md
- Compose: open
references/compose-testing.md
- UIAutomator (system/cross-app): open
references/uiautomator.md
Workflows
Add a New UI Test (Instrumented)
- Pick framework: Espresso (Views) vs Compose Testing vs UIAutomator boundary.
- Add stable selectors: View
id, Compose Modifier.testTag, system resource-id/content-desc.
- Control externals: fake/mock network + deterministic test data.
- Add waits: IdlingResources / Compose idling +
waitUntil (avoid sleeps).
- Run locally:
./gradlew connectedAndroidTest (or a single test via runner args).
Diagnose a Flaky Instrumented Test
- Confirm reproduces: run the test 10x; isolate to one device/API if needed.
- Remove nondeterminism: network, clock/timezone, locale, feature flags, animations.
- Replace sleeps with idling/explicit waits; validate your IdlingResource actually idles.
- Capture artifacts: logcat + screenshot + screen recording for failures.
- If still flaky, isolate app state (orchestrator + clear data) and bisect the interaction steps.
Add a CI Gate (Preferred: GMD)
- Configure GMD + ATD images (see
references/gradle-managed-devices.md).
- Run PR gate on a small matrix; expand via groups for nightly/release.
- Ensure artifacts upload on failure:
**/build/reports/androidTests/, screenshots/logcat.
ADB Commands (Triage)
# Screenshot
adb exec-out screencap -p > screenshot.png
# Screen recording
adb shell screenrecord /sdcard/demo.mp4
CI Integration
Preferred: Gradle Managed Devices (GMD). See references/gradle-managed-devices.md.
# .github/workflows/android.yml
name: Android CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- uses: gradle/actions/setup-gradle@v3
- run: ./gradlew test pixel6api34DebugAndroidTest
Navigating References
The reference guides are intentionally large; search within them instead of loading everything:
rg -n \"^## \" frameworks/shared-skills/skills/qa-testing-android/references/compose-testing.md
rg -n \"Idling|waitUntil|Synchronization\" frameworks/shared-skills/skills/qa-testing-android/references/compose-testing.md
rg -n \"RecyclerView|Intents\" frameworks/shared-skills/skills/qa-testing-android/references/espresso-patterns.md
Do / Avoid
Do
- Prefer orchestrator + per-test isolation for instrumented tests
- Use IdlingResources /
waitUntil for async waits
- Use Robot/Page Object patterns for readability and reuse
- Run a small device matrix on PRs; expand on nightly/release
Avoid
Thread.sleep() for synchronization
- Tests depending on live network/backends
- Flaky selectors (localized text, position-only selectors)
Resources
| Resource |
Purpose |
| references/espresso-patterns.md |
Espresso matchers, actions |
| references/compose-testing.md |
Compose testing guide |
| references/uiautomator.md |
UIAutomator patterns (system UI) |
| references/gradle-managed-devices.md |
Managed Devices for CI |
| references/screenshot-testing.md |
Visual regression for Android |
| references/test-orchestrator-patterns.md |
AndroidX Test Orchestrator patterns |
| references/android-ci-optimization.md |
CI pipeline optimization |
| data/sources.json |
Documentation links |
Templates
| Template |
Purpose |
| assets/template-android-test-checklist.md |
Stability checklist |
Related Skills
Fact-Checking
- Use web search/web fetch to verify current external facts, versions, pricing, deadlines, regulations, or platform behavior before final answers.
- Prefer primary sources; report source links and dates for volatile information.
- If web access is unavailable, state the limitation and mark guidance as unverified.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: qa-testing-android3description: Android testing with Espresso, UIAutomator, and Compose Testing. Use when building layered test strategy, device matrix, or CI integration. Use when this capability is needed.4---56# QA Testing (Android)78Android testing automation with Espresso, UIAutomator, and Compose Testing.910**Core References**: [Android Testing Docs](https://developer.android.com/training/testing), [Espresso](https://developer.android.com/training/testing/espresso), [Compose Testing](https://developer.android.com/develop/ui/compose/testing)1112## Quick Reference1314| Task | Command |15|------|---------|16| List emulators | `emulator -list-avds` |17| Start emulator | `emulator @<avd_name>` |18| List devices | `adb devices` |19| Install APK | `adb install -r <path-to-apk>` |20| Run unit tests | `./gradlew test` |21| Run instrumented tests (connected) | `./gradlew connectedAndroidTest` |22| Run instrumented tests (GMD) | `./gradlew <device><variant>AndroidTest` |23| List GMD tasks | `./gradlew tasks --all | rg -n \"AndroidTest|managedDevice|ManagedDevices\"` |24| Clear app data | `adb shell pm clear <applicationId>` |2526## Quick Start (2026 Defaults)2728- Prefer Gradle Managed Devices (GMD) + ATD images for CI; use `connectedAndroidTest` for local ad-hoc runs.29- Enable test isolation via AndroidX Test Orchestrator for instrumented tests.30- Disable animations via Gradle `testOptions` (preferred) instead of per-runner ADB steps.31- Keep selectors stable: `withId()` (Views), `testTag` (Compose), resource-id/content-desc (UIAutomator).3233Recommended Gradle defaults for stable instrumented tests (version catalog names vary by project):3435```kotlin36android {37 testOptions {38 animationsDisabled = true39 execution = "ANDROIDX_TEST_ORCHESTRATOR"40 }41}4243dependencies {44 androidTestUtil(libs.androidx.test.orchestrator)45}46```4748## When to Use4950- Debug or stabilize flaky Android UI tests51- Add Espresso tests for View-based UIs52- Add Compose UI tests for composables53- Add UIAutomator tests for system UI or cross-app flows54- Set up an Android test gate in CI5556## Inputs to Gather5758- UI stack: Views, Compose, or mixed59- Test layer: unit, Robolectric, instrumented UI, UIAutomator/system60- CI target: PR gate vs nightly vs release; emulator vs device farm61- Device matrix: min/target API, form factors, locales (if relevant)62- Flake symptoms: timeouts, missing nodes, idling/sync, device-only issues63- App seams: DI hooks for fakes, feature flags, test accounts/test data6465## Testing Layers6667| Layer | Framework | Scope |68|-------|-----------|-------|69| Unit | JUnit + Mockito | JVM, no Android |70| Unit (Android) | Robolectric | JVM, simulated |71| UI (Views) | Espresso | Instrumented |72| UI (Compose) | Compose Testing | Instrumented |73| System | UIAutomator | Cross-app |7475## Core Principles (Stability)7677### Device Matrix7879- Default: emulators for PR gates; real devices for release80- Cover: min supported API level, target API level, plus tablet/foldable if supported8182### Flake Control8384- Prefer Gradle `testOptions { animationsDisabled = true }` for instrumented tests85- Use AndroidX Test Orchestrator to isolate state and recover from crashes86- Use IdlingResources / Compose idling + `waitUntil` instead of sleeps87- Mock network with `MockWebServer` (or your DI fake) and avoid live backends88- Reset app state per test (test account/data, storage, feature flags)8990## Writing Tests9192- Espresso (Views): open `references/espresso-patterns.md`93- Compose: open `references/compose-testing.md`94- UIAutomator (system/cross-app): open `references/uiautomator.md`9596## Workflows9798### Add a New UI Test (Instrumented)99100- Pick framework: Espresso (Views) vs Compose Testing vs UIAutomator boundary.101- Add stable selectors: View `id`, Compose `Modifier.testTag`, system `resource-id`/`content-desc`.102- Control externals: fake/mock network + deterministic test data.103- Add waits: IdlingResources / Compose idling + `waitUntil` (avoid sleeps).104- Run locally: `./gradlew connectedAndroidTest` (or a single test via runner args).105106### Diagnose a Flaky Instrumented Test107108- Confirm reproduces: run the test 10x; isolate to one device/API if needed.109- Remove nondeterminism: network, clock/timezone, locale, feature flags, animations.110- Replace sleeps with idling/explicit waits; validate your IdlingResource actually idles.111- Capture artifacts: logcat + screenshot + screen recording for failures.112- If still flaky, isolate app state (orchestrator + clear data) and bisect the interaction steps.113114### Add a CI Gate (Preferred: GMD)115116- Configure GMD + ATD images (see `references/gradle-managed-devices.md`).117- Run PR gate on a small matrix; expand via groups for nightly/release.118- Ensure artifacts upload on failure: `**/build/reports/androidTests/`, screenshots/logcat.119120## ADB Commands (Triage)121122```bash123# Screenshot124adb exec-out screencap -p > screenshot.png125126# Screen recording127adb shell screenrecord /sdcard/demo.mp4128```129130## CI Integration131132Preferred: Gradle Managed Devices (GMD). See `references/gradle-managed-devices.md`.133134```yaml135# .github/workflows/android.yml136name: Android CI137on: [push, pull_request]138jobs:139 test:140 runs-on: ubuntu-latest141 steps:142 - uses: actions/checkout@v4143 - uses: actions/setup-java@v4144 with:145 java-version: '17'146 distribution: 'temurin'147 - uses: gradle/actions/setup-gradle@v3148 - run: ./gradlew test pixel6api34DebugAndroidTest149```150151## Navigating References152153The reference guides are intentionally large; search within them instead of loading everything:154155- `rg -n \"^## \" frameworks/shared-skills/skills/qa-testing-android/references/compose-testing.md`156- `rg -n \"Idling|waitUntil|Synchronization\" frameworks/shared-skills/skills/qa-testing-android/references/compose-testing.md`157- `rg -n \"RecyclerView|Intents\" frameworks/shared-skills/skills/qa-testing-android/references/espresso-patterns.md`158159## Do / Avoid160161### Do162163- Prefer orchestrator + per-test isolation for instrumented tests164- Use IdlingResources / `waitUntil` for async waits165- Use Robot/Page Object patterns for readability and reuse166- Run a small device matrix on PRs; expand on nightly/release167168### Avoid169170- `Thread.sleep()` for synchronization171- Tests depending on live network/backends172- Flaky selectors (localized text, position-only selectors)173174## Resources175176| Resource | Purpose |177|----------|---------|178| [references/espresso-patterns.md](references/espresso-patterns.md) | Espresso matchers, actions |179| [references/compose-testing.md](references/compose-testing.md) | Compose testing guide |180| [references/uiautomator.md](references/uiautomator.md) | UIAutomator patterns (system UI) |181| [references/gradle-managed-devices.md](references/gradle-managed-devices.md) | Managed Devices for CI |182| [references/screenshot-testing.md](references/screenshot-testing.md) | Visual regression for Android |183| [references/test-orchestrator-patterns.md](references/test-orchestrator-patterns.md) | AndroidX Test Orchestrator patterns |184| [references/android-ci-optimization.md](references/android-ci-optimization.md) | CI pipeline optimization |185| [data/sources.json](data/sources.json) | Documentation links |186187## Templates188189| Template | Purpose |190|----------|---------|191| [assets/template-android-test-checklist.md](assets/template-android-test-checklist.md) | Stability checklist |192193## Related Skills194195| Skill | Purpose |196|-------|---------|197| [software-mobile](../software-mobile/SKILL.md) | Android development |198| [qa-testing-strategy](../qa-testing-strategy/SKILL.md) | Test strategy |199| [qa-testing-mobile](../qa-testing-mobile/SKILL.md) | Cross-platform mobile |200201## Fact-Checking202203- Use web search/web fetch to verify current external facts, versions, pricing, deadlines, regulations, or platform behavior before final answers.204- Prefer primary sources; report source links and dates for volatile information.205- If web access is unavailable, state the limitation and mark guidance as unverified.206207---208> Converted and distributed by [TomeVault](https://tomevault.io/claim/vasilyu1983) — claim your Tome and manage your conversions.209<!-- tomevault:4.0:skill_md:2026-04-11 -->