Goal: cover behavior at the cheapest layer that proves it.
Use for:
- adding tests to a web app or feature
- deciding what to unit test vs. integration vs. e2e
- replacing brittle tests that break on refactors
Workflow:
- Identify the behavior and its user-visible contract.
- Choose the lowest layer that can verify it honestly.
- Unit test pure logic; integration test wiring; e2e the critical paths.
- Set up real dependencies where feasible; mock only true boundaries.
- Make tests deterministic: control time, network, and data.
- Run, confirm meaningful failure, then keep green.
Layer guidance:
- unit: pure functions, reducers, validation
- integration: components with real children, API handlers with a real db
- e2e: signup, checkout, and other revenue-critical flows
Rules:
- test behavior, not implementation detail
- do not mock what you are trying to verify
- keep e2e few and high-value; they are slow and flaky-prone
- a test that never fails has no value