Mobile Test Automation Best Practices (2026)
Mobile test automation succeeds or fails on discipline. The frameworks are good enough — Appium, Espresso, XCUITest all mature. The teams that succeed have chosen a sensible strategy, built on solid p
Mobile test automation succeeds or fails on discipline. The frameworks are good enough — Appium, Espresso, XCUITest all mature. The teams that succeed have chosen a sensible strategy, built on solid practices, and committed to maintenance. This guide distills those practices.
The core principles
- Favor fast tests. Unit > integration > UI. Aim 70/20/10.
- Stable locators. Every flake is a locator problem or a timing problem.
- One thing per test. Each test asserts one outcome.
- No shared state. Tests run in any order.
- Fast feedback. CI runs < 15 minutes ideally.
Locator strategies (in order of preference)
- Accessibility ID (iOS) / resource-id (Android) — stable, semantic
- Test ID attribute — a11y-friendly
testTag(Compose) orcontentDescription - Text match — fine for stable text (avoid user-editable)
- XPath — last resort, brittle on UI changes
Avoid: index-based (//Button[2]), class-only, or relative-to-parent-index selectors.
Synchronization
- Never
Thread.sleep. Wait for conditions. - Explicit waits with reasonable timeouts (10-15s)
- IdlingResource (Espresso) for custom async work
- WebDriverWait (Appium) with expected conditions
Data
- Fresh per test. Set up account, user, data at test start. Tear down after.
- Known test users. Dedicated accounts with pre-set state for login tests.
- Backend fixtures. Faker for realistic random data. Stable seed for reproducibility.
- Cleanup in tearDown. Leaked state → flaky future tests.
Structure
Page Object Pattern
class LoginScreen(val driver: AppiumDriver) {
private val username = By.id("username")
private val password = By.id("password")
private val submit = By.id("submit")
fun login(user: String, pass: String) {
driver.findElement(username).sendKeys(user)
driver.findElement(password).sendKeys(pass)
driver.findElement(submit).click()
}
}
Tests become readable; locators change in one place.
Screen Play
For larger apps: tasks, abilities, questions. Tests describe user journeys.
BDD with Gherkin
Natural-language tests if stakeholders read them. Cost is maintenance of step definitions.
CI integration
- Run on every PR (critical subset, < 10 min)
- Full suite before release (~ 45 min acceptable)
- Smoke test on nightly builds
- Release-candidate full-matrix across devices
Flake management
- Retry once. No more. (More masks real bugs.)
- Quarantine zone for known-flaky tests — they do not block merges but are tracked.
- Weekly triage: fix or delete flaky tests.
- Metric: flake rate per week. Target < 1%.
Device strategy
- Real devices for release gate. Emulators miss real-world bugs.
- Emulators for PR-gate fast feedback. Free, parallel, predictable.
- Cross-device matrix in release candidate — key device tiers.
- Cloud provider (Sauce, BrowserStack, SUSA remote agent) for scale.
Reporting
- Pass/fail dashboard accessible to team
- Flake rate visible
- Coverage by screen / flow
- Time-to-fix for broken tests (the team's metric)
Anti-patterns
- Recording macros without refactoring. Brittle.
- 100% UI test coverage goal. Diminishing returns.
- Test every permutation. Boundary cases, not exhaustive.
- "Temporary" disabled tests. Permanent decay.
- No test for new feature. Coverage gap grows.
How SUSA fits
SUSA generates Appium / Playwright scripts from exploration. These follow many best practices automatically:
- Multiple fallback locator strategies
- Explicit waits (not sleeps)
- Per-session isolation
- Outcome verification
The generated scripts are a starting point; teams customize for their domain-specific assertions.
susatest-agent test myapp.apk --persona curious --steps 200 --generate-scripts
Maturity checklist
- [ ] < 10 min PR-gate test run
- [ ] < 1% flake rate
- [ ] Locators use stable IDs everywhere
- [ ] Page objects abstract UI changes
- [ ] Every feature has at least one regression test
- [ ] Test results visible in PR UI
- [ ] Weekly flake triage meeting
- [ ] SUSA or exploration-based coverage for unknowns
Automation is a discipline, not a feature. Invest continuously; reap over quarters.
Test Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free