"We have tests" can mean almost anything on a mobile project: from three unit tests for date formatting to two hundred UI scenarios that fail every other run and that everyone ignores. Neither extreme protects you from regressions. The question isn't whether to write tests, but which ones, how many, and in what order.
This article explains how we at Mosmox build a testing strategy for iOS and Android: what belongs on each level of the pyramid, where to start on a project with no tests, how to tame flaky UI tests and how much time to budget.
The test pyramid: the classic model and what's different on mobile
Mike Cohn popularised the pyramid: lots of fast, cheap unit tests at the base, fewer integration tests in the middle, and a small number of end-to-end tests through the UI at the top. The model is explored in depth in The Practical Test Pyramid on Martin Fowler's site.
Android's documentation uses similar language: small, medium and large tests, defined by how much code they exercise and where they run. The logic is simple: the higher a test sits, the slower and costlier it is to maintain and the more often it fails spuriously — but the closer it gets to the real user experience.
Mobile adds two factors. First, UI tests need an emulator or simulator, which means CI minutes and start-up time. Second, mobile bugs often live at the boundary with the platform: permissions, screen lifecycle, rotation, process death and restoration. That makes the middle of the pyramid more important for mobile apps than for many backends.
What each level covers
| Level | What it checks | Tools | Speed | Rough share |
|---|---|---|---|---|
| Unit | ViewModels, use cases, validation, formatting, calculations, mappers | JUnit, Kotest, MockK; XCTest, Swift Testing | Milliseconds | 60–75% |
| Integration | Repository + database, network layer against a fake server, cross-module navigation | Robolectric, in-memory Room, MockWebServer; XCTest with URLProtocol stubs | Seconds | 15–30% |
| UI component / snapshot | A single screen or component in isolation, visual regressions | Compose UI testing, Paparazzi, Roborazzi; swift-snapshot-testing | Seconds | 5–15% |
| End-to-end | Critical journeys through the real UI and a test backend | Espresso, UI Automator, XCUITest, Maestro | Minutes | 5–10% |
The shares are a guideline from our projects, not a rule. One principle matters more than percentages: write each check at the lowest level where it can be written at all. If email validation can be covered by a unit test, it has no business living in a UI scenario.
Unit tests: a foundation that needs the right architecture
Unit tests are only cheap when the code is ready for them. If business logic lives inside an Activity, Fragment or SwiftUI View, you can only test it through the UI — and the pyramid flips. So testability is an architectural requirement for us: logic in ViewModels and use cases, dependencies passed through constructors, time, network and storage hidden behind interfaces.
What to cover with unit tests first:
- calculations involving money, discounts, taxes and currencies;
- access rules: what free and paying users can see;
- screen state transitions: loading → content → error → empty;
- parsing and mapping API responses, including incomplete or malformed data;
- date and time-zone logic — one of the most frequent bug sources on our projects.
On iOS, consider Swift Testing, introduced with Xcode 16, for new code: parameterised tests and clearer failure messages cut boilerplate. XCTest remains necessary for UI tests and existing suites.
Integration and snapshot tests: the sweet spot
Integration tests prove the layers actually work together: the repository writes to and reads from the database correctly, a schema migration doesn't lose data, the network layer handles a 401 and retries after refreshing the token. This is where you catch bugs that mock-heavy unit tests miss.
On Android, Robolectric runs tests against the Android framework on the JVM without an emulator — an order of magnitude faster than instrumented tests. For networking we use a fake server with recorded responses, so tests don't depend on the state of staging and don't break when someone edits test data.
Snapshot tests compare a rendered screen with a reference image. They're excellent at catching visual regressions: broken padding, truncated text in a long localisation, wrong colours in dark mode. One snapshot test can check a component in ten states — light and dark theme, large font, right-to-left language — in a few seconds.
End-to-end: few, but the most important
E2E tests are the most expensive. They're slow, depend on a test environment and are the most likely to be flaky. Google found that about 1.5% of all test runs in the company produced a flaky result, and roughly 16% of tests showed some level of flakiness. Mobile UI tests usually have it worse.
So we cover only the 5–10 journeys without which the business stops:
- sign-up and sign-in;
- the core product action (ordering, booking, creating an entry);
- payment or subscription purchase in a sandbox;
- account recovery;
- upgrading from the previous version with existing data.
For a quick start we often pick Maestro: flows are written in YAML, work on both platforms and wait for elements automatically, which reduces flakiness. Espresso and XCUITest remain the choice for deep integration with the codebase.
How to remove flakiness
- No fixed sleeps — only waits for a specific element state.
- Animations disabled on test devices.
- Every test creates its own data and doesn't depend on execution order.
- A flaky test is quarantined immediately with a ticket to fix it, not re-run "until it passes".
What to automate first on a project with no tests
Many projects come to us with no tests at all. Writing everything at once burns the team out and halts feature work. We go in stages:
| Stage | What we do | Duration (estimate) | Outcome |
|---|---|---|---|
| 1 | Run tests in CI on every pull request, even if there are only a handful | 1–2 days | Infrastructure that keeps tests from rotting |
| 2 | 3–5 E2E tests for critical journeys as a pre-release smoke suite | 3–5 days | Protection against the costliest regressions |
| 3 | Unit tests for money, access rules and screen states | Ongoing, 10–20% of each task | Coverage where a bug costs most |
| 4 | Rule: every fixed bug gets a test that reproduces it | Ongoing | Bugs don't come back |
| 5 | Snapshot tests for the design system and key screens | 3–7 days | Control over visual regressions |
Note that stage 2 temporarily inverts the pyramid by starting at the top. It's a deliberate trade-off: in code not designed for testing, a few E2E journeys give the most protection for the least time, and unit tests arrive alongside refactoring.
Metrics: how to tell your tests are working
- PR pipeline duration. Target: under 10–15 minutes. Any longer and developers start working around the checks.
- Flaky test rate. If more than 1–2% of runs fail without code changes, trust in the suite collapses.
- Production regressions. How many post-release bugs involve features that previously worked. This is the main measure of test value.
- Code coverage. Useful as an indicator of untested areas, harmful as a KPI: an "80% coverage" mandate breeds tests that assert nothing.
Common mistakes
- The inverted pyramid. Hundreds of UI tests and no unit tests; the suite takes an hour and fails for a different reason every time.
- Testing the mocks. The test verifies the mock returned what it was told to return, not how the code behaves.
- Depending on staging. Tests fail whenever someone changes data on the test server.
- No migration tests. A database schema update that wipes user data is one of the most painful bugs, because once released it can't be rolled back.
- Tests nobody runs. If a suite isn't wired into CI, it goes stale within weeks.
Testing strategy checklist
- Tests run automatically on every pull request, and failures block the merge.
- Business logic is pulled out of the UI layer and covered by unit tests.
- The network layer and database have integration tests, migrations included.
- Critical journeys (sign-in, core action, payment) are covered by E2E tests.
- Key screens have snapshot tests for dark mode and large fonts.
- Flaky tests are quarantined with a ticket to fix them.
- Every fixed bug gets a regression test.
- The PR pipeline takes no longer than 15 minutes.
Sources: The Practical Test Pyramid (martinfowler.com); Android: Fundamentals of testing; Apple XCTest; Swift Testing; Google Testing Blog: Flaky Tests at Google; Maestro; Firebase Test Lab.



