Mobile Testing
What This Does
Provides comprehensive mobile testing guidance across frameworks and platforms. Covers unit testing, integration testing, and end-to-end testing for React Native, Flutter, SwiftUI, and Jetpack Compose. Includes CI pipeline setup for automated mobile test runs.
Instructions
Assess the testing needs. Determine:
- Framework: React Native, Flutter, SwiftUI, or Jetpack Compose?
- What needs testing? (unit, integration, E2E, visual)
- Current test coverage and gaps
- CI/CD platform (GitHub Actions, Bitrise, CircleCI)
- Device targets (simulators only, or real device farms?)
Choose the right testing framework.
React Native:
| Level |
Framework |
Use For |
| Unit |
Jest + React Native Testing Library |
Components, hooks, utilities |
| E2E |
Detox |
Full app automation on simulators |
| E2E |
Maestro |
Flow-based testing with YAML |
Flutter:
| Level |
Framework |
Use For |
| Unit |
flutter_test |
Dart functions, providers, blocs |
| Widget |
flutter_test |
Individual widget behavior |
| Integration |
integration_test |
Full app flows on device |
| Golden |
golden_toolkit |
Visual regression snapshots |
iOS (SwiftUI):
| Level |
Framework |
Use For |
| Unit |
XCTest |
Swift logic, ViewModels |
| UI |
XCUITest |
SwiftUI view automation |
| Snapshot |
swift-snapshot-testing |
Visual regression |
Android (Compose):
| Level |
Framework |
Use For |
| Unit |
JUnit 5 + MockK |
Kotlin logic, ViewModels |
| UI |
Compose UI Test |
Composable interaction testing |
| E2E |
Espresso |
Full app automation |
Write unit tests first. For every framework:
// Pattern: Arrange -> Act -> Assert
// Test pure logic, ViewModels, repositories, utilities
// Mock external dependencies (network, storage, platform APIs)
// Aim for 80%+ coverage on business logic
Write E2E tests for critical flows. Focus on:
- Onboarding / signup / login
- Core user journey (the thing users do most)
- Payment / checkout flows
- Push notification handling
- Deep link navigation
- Offline behavior
Maestro example (cross-platform E2E):
# flows/login.yaml
appId: com.example.app
---
- launchApp
- tapOn: "Email"
- inputText: "user@example.com"
- tapOn: "Password"
- inputText: "password123"
- tapOn: "Sign In"
- assertVisible: "Welcome"
- assertVisible: "Dashboard"
Detox example (React Native E2E):
describe('Login Flow', () => {
beforeAll(async () => {
await device.launchApp();
});
it('should login successfully', async () => {
await element(by.id('email-input')).typeText('user@example.com');
await element(by.id('password-input')).typeText('password123');
await element(by.id('login-button')).tap();
await expect(element(by.text('Welcome'))).toBeVisible();
});
});
CI integration. Set up automated test runs:
- Unit tests: run on every PR
- E2E tests: run on merge to main or release branches
- Use simulators/emulators in CI (GitHub Actions has macOS runners)
- For real device testing: Firebase Test Lab, AWS Device Farm, or BrowserStack
Output Format
When setting up tests:
- Provide test file templates with the correct imports and setup
- Include CI configuration (GitHub Actions workflow YAML)
- List required dev dependencies to install
- Provide a test naming convention guide
## Test Setup Complete
### Installed
- {framework}: {version}
- {mocking library}: {version}
### Test Structure
{directory tree of test files}
### Run Commands
- Unit: `{command}`
- E2E: `{command}`
- Coverage: `{command}`
### CI Pipeline
{link to or contents of CI config file}
Tips
- Maestro is the fastest way to get E2E tests running across platforms — YAML syntax, no code
- For React Native, Detox is more powerful but harder to set up than Maestro
- Test on real devices before release — simulator-only testing misses real-world issues
- Use test IDs (
testID in RN, Modifier.testTag in Compose) instead of text matchers
- Flaky tests are worse than no tests — invest in test stability
- Golden/snapshot tests catch visual regressions that functional tests miss
- Run E2E tests against a staging API, not production — seed test data reliably
1---2name: mobile-testing3description: Mobile testing strategies and frameworks — Detox, Maestro, XCTest, Espresso, unit testing, and CI integration.4---56# Mobile Testing78## What This Does910Provides comprehensive mobile testing guidance across frameworks and platforms. Covers unit testing, integration testing, and end-to-end testing for React Native, Flutter, SwiftUI, and Jetpack Compose. Includes CI pipeline setup for automated mobile test runs.1112## Instructions13141. **Assess the testing needs.** Determine:15 - Framework: React Native, Flutter, SwiftUI, or Jetpack Compose?16 - What needs testing? (unit, integration, E2E, visual)17 - Current test coverage and gaps18 - CI/CD platform (GitHub Actions, Bitrise, CircleCI)19 - Device targets (simulators only, or real device farms?)20212. **Choose the right testing framework.**2223 **React Native:**24 | Level | Framework | Use For |25 |-------|-----------|---------|26 | Unit | Jest + React Native Testing Library | Components, hooks, utilities |27 | E2E | Detox | Full app automation on simulators |28 | E2E | Maestro | Flow-based testing with YAML |2930 **Flutter:**31 | Level | Framework | Use For |32 |-------|-----------|---------|33 | Unit | flutter_test | Dart functions, providers, blocs |34 | Widget | flutter_test | Individual widget behavior |35 | Integration | integration_test | Full app flows on device |36 | Golden | golden_toolkit | Visual regression snapshots |3738 **iOS (SwiftUI):**39 | Level | Framework | Use For |40 |-------|-----------|---------|41 | Unit | XCTest | Swift logic, ViewModels |42 | UI | XCUITest | SwiftUI view automation |43 | Snapshot | swift-snapshot-testing | Visual regression |4445 **Android (Compose):**46 | Level | Framework | Use For |47 |-------|-----------|---------|48 | Unit | JUnit 5 + MockK | Kotlin logic, ViewModels |49 | UI | Compose UI Test | Composable interaction testing |50 | E2E | Espresso | Full app automation |51523. **Write unit tests first.** For every framework:53 ```54 // Pattern: Arrange -> Act -> Assert55 // Test pure logic, ViewModels, repositories, utilities56 // Mock external dependencies (network, storage, platform APIs)57 // Aim for 80%+ coverage on business logic58 ```59604. **Write E2E tests for critical flows.** Focus on:61 - Onboarding / signup / login62 - Core user journey (the thing users do most)63 - Payment / checkout flows64 - Push notification handling65 - Deep link navigation66 - Offline behavior67685. **Maestro example (cross-platform E2E):**69 ```yaml70 # flows/login.yaml71 appId: com.example.app72 ---73 - launchApp74 - tapOn: "Email"75 - inputText: "user@example.com"76 - tapOn: "Password"77 - inputText: "password123"78 - tapOn: "Sign In"79 - assertVisible: "Welcome"80 - assertVisible: "Dashboard"81 ```82836. **Detox example (React Native E2E):**84 ```typescript85 describe('Login Flow', () => {86 beforeAll(async () => {87 await device.launchApp();88 });8990 it('should login successfully', async () => {91 await element(by.id('email-input')).typeText('user@example.com');92 await element(by.id('password-input')).typeText('password123');93 await element(by.id('login-button')).tap();94 await expect(element(by.text('Welcome'))).toBeVisible();95 });96 });97 ```98997. **CI integration.** Set up automated test runs:100 - Unit tests: run on every PR101 - E2E tests: run on merge to main or release branches102 - Use simulators/emulators in CI (GitHub Actions has macOS runners)103 - For real device testing: Firebase Test Lab, AWS Device Farm, or BrowserStack104105## Output Format106107When setting up tests:108- Provide test file templates with the correct imports and setup109- Include CI configuration (GitHub Actions workflow YAML)110- List required dev dependencies to install111- Provide a test naming convention guide112113```markdown114## Test Setup Complete115116### Installed117- {framework}: {version}118- {mocking library}: {version}119120### Test Structure121{directory tree of test files}122123### Run Commands124- Unit: `{command}`125- E2E: `{command}`126- Coverage: `{command}`127128### CI Pipeline129{link to or contents of CI config file}130```131132## Tips133134- Maestro is the fastest way to get E2E tests running across platforms — YAML syntax, no code135- For React Native, Detox is more powerful but harder to set up than Maestro136- Test on real devices before release — simulator-only testing misses real-world issues137- Use test IDs (`testID` in RN, `Modifier.testTag` in Compose) instead of text matchers138- Flaky tests are worse than no tests — invest in test stability139- Golden/snapshot tests catch visual regressions that functional tests miss140- Run E2E tests against a staging API, not production — seed test data reliably