GuideOpen

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 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 DefaultWhy It's Wrongโœ… Mobile-Correct
Jest-only testingMisses native layerJest + E2E on device
Enzyme patternsDeprecated, web-focusedReact Native Testing Library
Browser-based E2E (Cypress)Can't test native featuresDetox / Maestro
Mock everythingMisses integration bugsReal device testing
Ignore platform testsiOS/Android differPlatform-specific cases
Skip performance testsMobile perf is criticalProfile on low-end device
Test only happy pathMobile has more edge casesOffline, permissions, interrupts
100% unit test coverageFalse securityPyramid balance
Copy web testing patternsDifferent environmentMobile-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

ToolPlatformSpeedReliabilityUse When
JestRNโšกโšกโšกโšกโšกโšกUnit tests, logic
RNTLRNโšกโšกโšกโšกโšกComponent tests
flutter_testFlutterโšกโšกโšกโšกโšกโšกWidget tests
DetoxRNโšกโšกโšกโšกโšกE2E, critical flows
MaestroBothโšกโšกโšกโšกE2E, cross-platform
AppiumBothโšกโšก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?

LevelWhy 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?

AreaiOS BehaviorAndroid BehaviorTest Both?
Back navigationEdge swipeSystem back buttonโœ… YES
PermissionsAsk once, settingsAsk each time, rationaleโœ… YES
KeyboardDifferent appearanceDifferent behaviorโœ… YES
Date pickerWheel/modalMaterial dialogโš ๏ธ If custom UI
Push formatAPNs payloadFCM payloadโœ… YES
Deep linksUniversal LinksApp Linksโœ… YES
GesturesSome uniqueMaterial 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

ScenarioWhat to Verify
Start app offlineShows cached data or offline message
Go offline mid-actionAction queued, not lost
Come back onlineQueue synced, no duplicates
Slow network (2G)Loading states, timeouts work
Flaky networkRetry 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

MetricTargetHow to Measure
App startup< 2 secondsProfiler, Flashlight
Screen transition< 300msReact DevTools
List scroll60 FPSProfiler, feel
MemoryStable, no leaksInstruments / Android Profiler
Bundle sizeMinimizeMetro 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

ElementCheck
Interactive elementsHave accessibilityLabel
ImagesHave alt text or decorative flag
FormsLabels linked to inputs
ButtonsRole = button
Touch targetsโ‰ฅ 44x44 (iOS) / 48x48 (Android)
Color contrastWCAG 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

StageTestsDevices
PRUnit + ComponentNone (fast)
Merge to main+ IntegrationSimulator/Emulator
Pre-release+ E2EReal devices (farm)
NightlyFull suiteDevice farm

Device Farm Options

ServiceProsCons
Firebase Test LabFree tier, Google devicesAndroid focus
AWS Device FarmWide selectionExpensive
BrowserStackGood UXExpensive
Local devicesFree, reliableLimited 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:

  1. What could break? โ†’ Test that
  2. What's critical for users? โ†’ E2E test that
  3. What's complex logic? โ†’ Unit test that
  4. What's platform-specific? โ†’ Test on both platforms
  5. 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.

Source: https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/creative-design/mobile-design/mobile-testing.md

Author: davila7, Claude Code templates (davila7). License: MIT.

Shown here with formatting for the web. Keep the author and license notice when you reuse it.

Related entries

There are more like this in the members library

The Claude Code library holds 13,843 entries. Members can search all of them by meaning and read every one in full.