Mosmoxmosmox

Mosmox journal

In focus — testing.

A selection of publications grouped under the testing tag.

The Mobile Test Pyramid: Unit, Integration and UI Tests, and What to Automate First

The Mobile Test Pyramid: Unit, Integration and UI Tests, and What to Automate First

"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

LevelWhat it checksToolsSpeedRough share
UnitViewModels, use cases, validation, formatting, calculations, mappersJUnit, Kotest, MockK; XCTest, Swift TestingMilliseconds60–75%
IntegrationRepository + database, network layer against a fake server, cross-module navigationRobolectric, in-memory Room, MockWebServer; XCTest with URLProtocol stubsSeconds15–30%
UI component / snapshotA single screen or component in isolation, visual regressionsCompose UI testing, Paparazzi, Roborazzi; swift-snapshot-testingSeconds5–15%
End-to-endCritical journeys through the real UI and a test backendEspresso, UI Automator, XCUITest, MaestroMinutes5–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:

  1. sign-up and sign-in;
  2. the core product action (ordering, booking, creating an entry);
  3. payment or subscription purchase in a sandbox;
  4. account recovery;
  5. 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:

StageWhat we doDuration (estimate)Outcome
1Run tests in CI on every pull request, even if there are only a handful1–2 daysInfrastructure that keeps tests from rotting
23–5 E2E tests for critical journeys as a pre-release smoke suite3–5 daysProtection against the costliest regressions
3Unit tests for money, access rules and screen statesOngoing, 10–20% of each taskCoverage where a bug costs most
4Rule: every fixed bug gets a test that reproduces itOngoingBugs don't come back
5Snapshot tests for the design system and key screens3–7 daysControl 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

  1. The inverted pyramid. Hundreds of UI tests and no unit tests; the suite takes an hour and fails for a different reason every time.
  2. Testing the mocks. The test verifies the mock returned what it was told to return, not how the code behaves.
  3. Depending on staging. Tests fail whenever someone changes data on the test server.
  4. 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.
  5. 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.

Mobile App Accessibility: What a Product Team Should Check

Mobile App Accessibility: What a Product Team Should Check

Mobile app accessibility is not a special mode for a small group of people. It decides whether someone can read the text, tap a control, understand a message and finish a task under any conditions: with enlarged text, with a screen reader, one-handed on a bus or in bright sunlight.

Across our projects we see the same pattern: accessibility problems almost never arrive as a separate "accessibility ticket". They accumulate in components, colours and copy from the very first sprint, and fixing them right before release costs several times more. Below is what a product team can check on its own, with concrete thresholds, tools and an order of work.

Why accessibility is a product issue, not charity

According to the WHO, about 1.3 billion people, or 16% of the world's population, live with significant disability, and at least 2.2 billion have some form of vision impairment. Add situational limitations on top: a broken arm, a child in your arms, noise, glare on the screen, older age. An interface that works for a VoiceOver user usually works better for everyone else as well.

There is also a regulatory dimension. Since 28 June 2025 the European Accessibility Act applies in the EU: accessibility requirements cover, among others, e-commerce, banking services and transport apps sold on the EU market. Conformance is usually assessed against WCAG 2.1/2.2 level AA through the EN 301 549 standard. If your product targets European users, accessibility becomes a legal risk, not just a quality concern.

Minimum thresholds worth knowing by heart

Vague wording like "contrast is sufficient" doesn't survive a review. The team needs numbers that a tool can verify.

What we checkThresholdSource
Contrast of normal textat least 4.5:1WCAG 2.2, criterion 1.4.3 (AA)
Contrast of large text (18 pt and up, or 14 pt bold)at least 3:1WCAG 2.2, 1.4.3
Contrast of icons, field borders, component statesat least 3:1WCAG 2.2, 1.4.11
Touch target44×44 pt on iOS, 48×48 dp on AndroidApple HIG, Android accessibility guidelines
Text resizingup to 200% without loss of content or functionWCAG 2.2, 1.4.4; Android 14 allows font scaling up to 200%
Colour as information carriernever the only meansWCAG 2.2, 1.4.1
Visible focusfocus is always visible and not obscuredWCAG 2.2, 2.4.7 and 2.4.11

Note that the touch target is not the same as the icon size. An icon can be 24×24 dp as long as the invisible touch area around it is 48×48 dp. We covered target sizes and reach zones in more detail in our article on one-handed design.

The baseline checklist

Visual layer

  • Contrast of text, icons and field borders meets the thresholds in the table, including disabled and error states.
  • The interface works with the largest system font: iOS Dynamic Type up to the AX5 size, Android at 200% scale.
  • Status is never conveyed by colour alone: an error has text and an icon, not just a red border.
  • Animations are simplified when Reduce Motion (iOS) or "Remove animations" (Android) is on.

Semantic layer

  • Every interactive element has a meaningful name: not "button" but "Add to cart".
  • The element's role is announced correctly: a button as a button, a switch with its "on" or "off" state.
  • Decorative images are hidden from the screen reader; meaningful ones have a description.
  • Focus order follows reading order, and after a modal closes, focus returns to the element that opened it.

Content layer

  • Errors explain the problem and how to fix it, rather than showing a code.
  • Form fields have persistent labels, not just a placeholder that disappears while typing. More on that in our article on mobile forms.
  • Status changes (saved successfully, network error) are announced by the screen reader even when focus stays where it is.

How to test: a one-sprint routine

Automated checks find part of the problems — contrast, missing labels, small touch targets — but they don't replace real scenarios. That's why we recommend combining both approaches.

  1. Automated pass. On Android, run Accessibility Scanner on key screens and add AccessibilityChecks to your Espresso tests. On iOS, use Accessibility Inspector in Xcode and, since Xcode 15, the performAccessibilityAudit() method in UI tests.
  2. Screen reader. Walk through the three main scenarios with VoiceOver and TalkBack with your eyes closed or the screen curtain on. Log every point where you can't tell what's happening.
  3. Maximum font size. Set the system text size to the maximum and repeat the same scenarios. Look for truncated text, overlapping buttons and screens that don't scroll.
  4. Non-touch control. Check Switch Access on Android and Full Keyboard Access on iOS: can every element be reached, and is it clear where focus currently is?
  5. Physical conditions. Take the phone outside, lower the brightness, turn on greyscale. It's a five-minute test that finds contrast issues better than any mock-up.
  6. Real users. Once a quarter, invite at least two people who use a screen reader or magnification every day. Even one session reshapes backlog priorities.

Typical team mistakes

  • Accessibility at the end of the release. When the check happens a week before publishing, fixes get postponed "for later", and later never comes.
  • Custom components without semantics. A home-made toggle drawn from several views looks great, but for TalkBack it's a set of unnamed elements. Standard platform components get semantics for free.
  • Fixed heights for cards and buttons. This is exactly what breaks the interface with enlarged text: copy gets cut off and the action becomes unreachable.
  • Identical labels for different elements. Ten "More" buttons in a list don't help a screen reader user understand what each one refers to.
  • Trusting automation alone. A scanner won't tell you that the focus order is illogical or that an error message is confusing.

How to build accessibility into the process

The cheapest place for accessibility is the design system. If the button, text field and card already have correct contrast, minimum touch targets, semantic roles and behaviour under large text, every new screen inherits those properties automatically. Pay special attention to the primary action button: it's the element that most often becomes unreachable when text is scaled.

The second place is the Definition of Done. We add three short items: the screen has been walked through with VoiceOver or TalkBack, checked at maximum font size, and any new colours have been checked for contrast. That takes 15–20 minutes per feature but removes most regressions.

The third is design review. Annotate the mock-ups: focus order, screen reader labels, overflow behaviour. A developer shouldn't have to guess what an icon-only button should announce.

Product team checklist

  1. Define 3–5 key scenarios that must be fully accessible.
  2. Record the thresholds from the table above in the design system and developer guidelines.
  3. Add automated checks to CI: AccessibilityChecks for Espresso, performAccessibilityAudit() for XCTest.
  4. Put a manual screen reader and maximum-font check into the Definition of Done.
  5. Keep a dedicated tag for accessibility defects and review them during planning.
  6. Once a quarter, run a session with real users of assistive technologies.
  7. If the product ships to the EU market, verify WCAG 2.2 AA conformance in light of the European Accessibility Act.

Sources: Android Developers: What a great user experience looks like; Android Developers: Make apps more accessible; Apple Human Interface Guidelines: Accessibility; W3C: Web Content Accessibility Guidelines (WCAG) 2.2; WHO: Disability fact sheet; European Commission: European Accessibility Act.

Why Mobile Products Must Be Tested on Affordable Devices

Why Mobile Products Must Be Tested on Affordable Devices

An emulator on a powerful laptop and a flagship phone in a developer’s pocket create a false sense of quality. The app opens in a second, lists scroll smoothly, the camera focuses instantly. But a large share of the real audience uses phones with slower processors, less memory, cheaper storage and older OS versions — and that is exactly where problems the team never saw during development show up.

In our projects we keep seeing the same pattern: bug reports saying “it freezes”, “it crashes when I take a photo” or “it takes forever to load” almost always come from budget devices. That is why an affordable smartphone is not an optional extra for us but a mandatory part of the test fleet. Below is how we set up this kind of testing, which thresholds we use and which mistakes we recommend avoiding.

Why flagships and emulators are misleading

The difference between devices is not just CPU clock speed. Affordable phones have slower storage (often eMMC instead of UFS), so reading the database and unpacking resources at startup takes noticeably longer. Less RAM means the system kills background processes more aggressively: the user switches to a messenger, comes back, and the app starts from scratch, losing whatever they had typed. Under sustained load, cheaper chips overheat and throttle sooner, and some manufacturers add their own “battery optimisers” that stop background work.

Users do not perceive “low FPS” or “slow cold start” as separate technical events. They see a freeze, tap the button again, end up with a duplicate order or simply close the app. We covered why speed directly affects retention in our piece on Zomato’s experience.

What the Josh case study shows

A telling public example is Josh, an Indian short-video app whose story was published by the Android Developers team. The developers aimed for a consistent experience across high-end, mid-range and low-end devices and focused on cold start, because improving it automatically speeds up warm and hot starts as well.

  • The team profiled every block of code executed during startup and analysed system traces in Perfetto, Systrace and the Android Studio Profiler.
  • They disabled auto-initialisation of some third-party SDKs, removed legacy libraries and moved certain modules to the background.
  • They reduced the splash-screen drawables and optimised them for screen size.
  • Each change was validated in isolation by emulating cold starts and using Jetpack Macrobenchmark.

The result, according to the case study: startup became 30% faster for the average user and 3x faster for roughly 10% of users on older and low-end devices. Better bounce rates and retention helped Josh retain more than a million users compared with the baseline, and Play Store ratings trended upward. The key lesson: the biggest gains went to the people with the weakest phones.

Thresholds worth aiming for

To keep testing from becoming a subjective “feels slow”, you need numbers. Some of them are set by Google Play through Android vitals: exceeding the thresholds can reduce your app’s visibility in the store. Others are internal targets we use, and they should be read as studio experience.

MetricThresholdSource
Cold start (TTID)5 s or longer is considered excessiveAndroid vitals
Warm start2 s or longerAndroid vitals
Hot start1.5 s or longerAndroid vitals
User-perceived crash rate1.09% overall, 8% on a single phone modelAndroid vitals
User-perceived ANR rate0.47% overall, 8% on a single modelAndroid vitals
Frame budget≈16.7 ms at 60 Hz, ≈8.3 ms at 120 HzDisplay physics
Cold start on a budget devicetarget of 2–3 s to the first useful actionStudio target

Pay attention to the per-model thresholds. The average across all devices may look green while one popular budget model has crash rates of several percent — and that is a visibility and reputation problem in its own right.

Device matrix: the minimum to start with

The test fleet does not have to be large. Four or five devices are enough for us, provided they are chosen from data rather than from whatever happens to be lying around the office. Check the distribution of models, RAM and OS versions in Play Console, App Store Connect or your analytics.

  • One current flagship as the reference for design and animation.
  • One mid-range device running the Android version most common in your audience.
  • One affordable phone with 3–4 GB of RAM and slow storage.
  • The oldest iPhone still supported by your minimum iOS version.
  • If relevant, a device running Android Go edition, if you operate in markets where such phones are common.

A step-by-step testing process

  1. Define 5–7 key scenarios: first launch, sign-in, search, completing the core action, camera or file upload.
  2. Measure cold start on every device: on Android via the Displayed line in Logcat or Macrobenchmark, on iOS via Instruments. Repeat at least 10 times and take the median.
  3. Check scrolling of long lists, keyboard opening, image loading and screen rotation.
  4. Background the app, open a few heavy apps and return: form data and list position must survive.
  5. Throttle the network: speed profiles in the Android Emulator or Network Link Conditioner on iOS. Test switching between Wi‑Fi and mobile data.
  6. Repeat the key scenarios with battery saver on and a low battery level.
  7. Record not just the bug but the context: model, OS version, free memory, network state.

Common mistakes

  • Testing only debug builds. They are slower than release builds and distort measurements; measure performance on a release build with R8.
  • Initialising everything in Application.onCreate. Analytics, ads, support chat and an A/B platform at startup are a classic cause of slow launches, exactly as the Josh case shows.
  • Loading images at full resolution. On a weak device this is a direct route to an OutOfMemoryError.
  • Looking only at averages. Budget-device problems hide in the 90th and 95th percentiles.
  • Checking once before release. Performance regressions accumulate quietly, so measurements should be automated.

Pre-release checklist

  • Cold start on a budget device has been measured and is nowhere near the 5 s threshold.
  • Crash rate and ANR rate are below the Android vitals thresholds, including for your audience’s top models.
  • Form and navigation state is restored after process death.
  • Key scenarios have been run on a slow network and in battery saver mode.
  • Third-party SDKs not needed for the first screen are initialised lazily.
  • Startup metrics are tracked in production, not only in the test lab.

An affordable device is not a “lesser” user. It is a real environment in which the product has to keep its promise. Testing on it reduces abandonment and negative reviews, and with them the number of emergency fixes after release. After launch, look beyond downloads, at behaviour after install.

Sources: Android Developers: Josh app startup case study; Android vitals: core vitals and bad behavior thresholds; Android vitals: App startup time; Jetpack Macrobenchmark; Android: Build for Billions.

Journal

Ideas and products