Mobile testing is NOT web testing. Different constraints, different strategies. This file teaches WHEN to use each testing approach and WHY. Code examples are minimal - focus on decision-making.
Mobile Testing Patterns
Mobile testing is NOT web testing. Different constraints, different strategies. This file teaches WHEN to use each testing approach and WHY. Code examples are minimal - focus on decision-making.
๐ง MOBILE TESTING MINDSET
Mobile testing differs from web:
โโโ Real devices matter (emulators hide bugs)
โโโ Platform differences (iOS vs Android behavior)
โโโ Network conditions vary wildly
โโโ Battery/performance under test
โโโ App lifecycle (background, killed, restored)
โโโ Permissions and system dialogs
โโโ Touch interactions vs clicks
๐ซ AI MOBILE TESTING ANTI-PATTERNS
| โ AI Default | Why It's Wrong | โ
Mobile-Correct |
|---|
| Jest-only testing | Misses native layer | Jest + E2E on device |
| Enzyme patterns | Deprecated, web-focused | React Native Testing Library |
| Browser-based E2E (Cypress) | Can't test native features | Detox / Maestro |
| Mock everything | Misses integration bugs | Real device testing |
| Ignore platform tests | iOS/Android differ | Platform-specific cases |
| Skip performance tests | Mobile perf is critical | Profile on low-end device |
| Test only happy path | Mobile has more edge cases | Offline, permissions, interrupts |
| 100% unit test coverage | False security | Pyramid balance |
| Copy web testing patterns | Different environment | Mobile-specific tools |
1. Testing Tool Selection
Decision Tree
WHAT ARE YOU TESTING?
โ
โโโ Pure functions, utilities, helpers
โ โโโ Jest (unit tests)
โ โโโ No special mobile setup needed
โ
โโโ Individual components (isolated)
โ โโโ React Native โ React Native Testing Library
โ โโโ Flutter โ flutter_test (widget tests)
โ
โโโ Components with hooks, context, navigation
โ โโโ React Native โ RNTL + mocked providers
โ โโโ Flutter โ integration_test package
โ
โโโ Full user flows (login, checkout, etc.)
โ โโโ Detox (React Native, fast, reliable)
โ โโโ Maestro (Cross-platform, YAML-based)
โ โโโ Appium (Legacy, slow, last resort)
โ
โโโ Performance, memory, battery
โโโ Flashlight (RN performance)
โโโ Flutter DevTools
โโโ Real device profiling (Xcode/Android Studio)
Tool Comparison
| Tool | Platform | Speed | Reliability | Use When |
|---|
| Jest | RN | โกโกโก | โกโกโก | Unit tests, logic |
| RNTL | RN | โกโกโก | โกโก | Component tests |
| flutter_test | Flutter | โกโกโก | โกโกโก | Widget tests |
| Detox | RN | โกโก | โกโกโก | E2E, critical flows |
| Maestro | Both | โกโก | โกโก | E2E, cross-platform |
| Appium | Both | โก | โก | Legacy, last resort |
2. Testing Pyramid for Mobile
โโโโโโโโโโโโโโโโโ
โ E2E Tests โ 10%
โ (Real device) โ Slow, expensive, essential
โโโโโโโโโโโโโโโโโค
โ Integration โ 20%
โ Tests โ Component + context
โโโโโโโโโโโโโโโโโค
โ Component โ 30%
โ Tests โ Isolated UI
โโโโโโโโโโโโโโโโโค
โ Unit Tests โ 40%
โ (Jest) โ Pure logic
โโโโโโโโโโโโโโโโโ
Why This Distribution?
| Level | Why This % |
|---|
| E2E 10% | Slow, flaky, but catches integration bugs |
| Integration 20% | Tests real user flows without full app |
| Component 30% | Fast feedback on UI changes |
| Unit 40% | Fastest, most stable, logic coverage |
๐ด If you have 90% unit tests and 0% E2E, you're testing the wrong things.
3. What to Test at Each Level
Unit Tests (Jest)
โ
TEST:
โโโ Utility functions (formatDate, calculatePrice)
โโโ State reducers (Redux, Zustand stores)
โโโ API response transformers
โโโ Validation logic
โโโ Business rules
โ DON'T TEST:
โโโ Component rendering (use component tests)
โโโ Navigation (use integration tests)
โโโ Native modules (mock them)
โโโ Third-party libraries
Component Tests (RNTL / flutter_test)
โ
TEST:
โโโ Component renders correctly
โโโ User interactions (tap, type, swipe)
โโโ Loading/error/empty states
โโโ Accessibility labels exist
โโโ Props change behavior
โ DON'T TEST:
โโโ Internal implementation details
โโโ Snapshot everything (only key components)
โโโ Styling specifics (brittle)
โโโ Third-party component internals
Integration Tests
โ
TEST:
โโโ Form submission flows
โโโ Navigation between screens
โโโ State persistence across screens
โโโ API integration (with mocked server)
โโโ Context/provider interactions
โ DON'T TEST:
โโโ Every possible path (use unit tests)
โโโ Third-party services (mock them)
โโโ Backend logic (backend tests)
E2E Tests
โ
TEST:
โโโ Critical user journeys (login, purchase, signup)
โโโ Offline โ online transitions
โโโ Deep link handling
โโโ Push notification navigation
โโโ Permission flows
โโโ Payment flows
โ DON'T TEST:
โโโ Every edge case (too slow)
โโโ Visual regression (use snapshot tests)
โโโ Non-critical features
โโโ Backend-only logic
4. Platform-Specific Testing
What Differs Between iOS and Android?
| Area | iOS Behavior | Android Behavior | Test Both? |
|---|
| Back navigation | Edge swipe | System back button | โ
YES |
| Permissions | Ask once, settings | Ask each time, rationale | โ
YES |
| Keyboard | Different appearance | Different behavior | โ
YES |
| Date picker | Wheel/modal | Material dialog | โ ๏ธ If custom UI |
| Push format | APNs payload | FCM payload | โ
YES |
| Deep links | Universal Links | App Links | โ
YES |
| Gestures | Some unique | Material gestures | โ ๏ธ If custom |
Platform Testing Strategy
FOR EACH PLATFORM:
โโโ Run unit tests (same on both)
โโโ Run component tests (same on both)
โโโ Run E2E on REAL DEVICE
โ โโโ iOS: iPhone (not just simulator)
โ โโโ Android: Mid-range device (not flagship)
โโโ Test platform-specific features separately
5. Offline & Network Testing
Offline Scenarios to Test
| Scenario | What to Verify |
|---|
| Start app offline | Shows cached data or offline message |
| Go offline mid-action | Action queued, not lost |
| Come back online | Queue synced, no duplicates |
| Slow network (2G) | Loading states, timeouts work |
| Flaky network | Retry logic, error recovery |
How to Test Network Conditions
APPROACH:
โโโ Unit tests: Mock NetInfo, test logic
โโโ Integration: Mock API responses, test UI
โโโ E2E (Detox): Use device.setURLBlacklist()
โโโ E2E (Maestro): Use network conditions
โโโ Manual: Use Charles Proxy / Network Link Conditioner
6. Performance Testing
What to Measure
| Metric | Target | How to Measure |
|---|
| App startup | < 2 seconds | Profiler, Flashlight |
| Screen transition | < 300ms | React DevTools |
| List scroll | 60 FPS | Profiler, feel |
| Memory | Stable, no leaks | Instruments / Android Profiler |
| Bundle size | Minimize | Metro bundler analysis |
When to Performance Test
PERFORMANCE TEST:
โโโ Before release (required)
โโโ After adding heavy features
โโโ After upgrading dependencies
โโโ When users report slowness
โโโ On CI (optional, automated benchmarks)
WHERE TO TEST:
โโโ Real device (REQUIRED)
โโโ Low-end device (Galaxy A series, old iPhone)
โโโ NOT on emulator (lies about performance)
โโโ With production-like data (not 3 items)
7. Accessibility Testing
What to Verify
| Element | Check |
|---|
| Interactive elements | Have accessibilityLabel |
| Images | Have alt text or decorative flag |
| Forms | Labels linked to inputs |
| Buttons | Role = button |
| Touch targets | โฅ 44x44 (iOS) / 48x48 (Android) |
| Color contrast | WCAG AA minimum |
How to Test
AUTOMATED:
โโโ React Native: jest-axe
โโโ Flutter: Accessibility checker in tests
โโโ Lint rules for missing labels
MANUAL:
โโโ Enable VoiceOver (iOS) / TalkBack (Android)
โโโ Navigate entire app with screen reader
โโโ Test with increased text size
โโโ Test with reduced motion
8. CI/CD Integration
What to Run Where
| Stage | Tests | Devices |
|---|
| PR | Unit + Component | None (fast) |
| Merge to main | + Integration | Simulator/Emulator |
| Pre-release | + E2E | Real devices (farm) |
| Nightly | Full suite | Device farm |
Device Farm Options
| Service | Pros | Cons |
|---|
| Firebase Test Lab | Free tier, Google devices | Android focus |
| AWS Device Farm | Wide selection | Expensive |
| BrowserStack | Good UX | Expensive |
| Local devices | Free, reliable | Limited variety |
๐ MOBILE TESTING CHECKLIST
Before PR
- [ ] Unit tests for new logic
- [ ] Component tests for new UI
- [ ] No console.logs in tests
- [ ] Tests pass on CI
Before Release
- [ ] E2E on real iOS device
- [ ] E2E on real Android device
- [ ] Tested on low-end device
- [ ] Offline scenarios verified
- [ ] Performance acceptable
- [ ] Accessibility verified
What to Skip (Consciously)
- [ ] 100% coverage (aim for meaningful coverage)
- [ ] Every visual permutation (use snapshots sparingly)
- [ ] Third-party library internals
- [ ] Backend logic (separate tests)
๐ฏ Testing Questions to Ask
Before writing tests, answer:
- What could break? โ Test that
- What's critical for users? โ E2E test that
- What's complex logic? โ Unit test that
- What's platform-specific? โ Test on both platforms
- What happens offline? โ Test that scenario
Remember: Good mobile testing is about testing the RIGHT things, not EVERYTHING. A flaky E2E test is worse than no test. A failing unit test that catches a bug is worth 100 passing trivial tests.