tezvyn:

Layered testing strategy for a large RN app

AI-drafted, machine-checkedSource: interviewintermediate
WHAT IT TESTS

understanding the test pyramid in RN.

OUTLINE

many fast Jest unit tests, fewer RNTL component tests on behavior, few Detox/Maestro E2E on critical flows.

WHAT THIS TESTS The interviewer is checking whether you can design a test suite that gives fast feedback while still catching real regressions, and whether you understand the cost tradeoffs of each layer in a mobile context.

A GOOD ANSWER COVERS Structure tests as a pyramid. The base is many fast unit tests in Jest covering pure functions, reducers, selectors, and custom hooks with no native dependencies; these run in milliseconds and gate every commit. The middle layer uses React Native Testing Library to render components and assert what the user sees, querying by accessible role or text and firing press and input events while mocking network and native modules. The thin top is end-to-end with Detox or Maestro, exercising only critical journeys like sign-in, checkout, or onboarding on a simulator or device. You also gate pull requests with lint, type checks, and the unit and component layers, while running the slower E2E suite on a schedule or pre-release to avoid blocking developers.

COMMON WRONG ANSWERS Proposing mostly E2E tests inverts the pyramid and yields a slow, flaky suite. Snapshot testing every component creates brittle noise that developers rubber-stamp. Testing internal state or calling private methods couples tests to implementation. Mocking everything in component tests until nothing real runs gives false confidence.

LIKELY FOLLOW-UPS How do you keep E2E from being flaky? Use stable testID selectors, explicit waits over fixed sleeps, and deterministic test data. How do you measure suite health? Track coverage on logic, plus flake rate and runtime per layer. How do you handle native modules in unit tests? Provide Jest mocks or a manual __mocks__ implementation.

ONE CONCRETE EXAMPLE A payments screen: unit-test the fee calculator and currency formatter in Jest, component-test the form with RNTL to verify validation errors appear and the submit button disables, and add a single Detox journey that logs in, enters a card, and confirms the success screen. The fast layers run on every push; the Detox journey runs nightly and before release.

Read the original → gigson.co

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.