System Designmedium
Frontend unit and end-to-end testing strategy
Design a practical testing strategy for a production frontend app. Cover unit tests, component tests, integration tests, E2E tests, mocks, accessibility checks, and CI trade-offs.
Asked at Tenable
Answer
Interview framing: Testing should protect important behavior without making refactors painful. The pyramid is useful, but product risk matters more than dogma.
Testing layers:
- Unit tests:
- Pure functions, reducers, validators, formatters, permissions, and state transitions.
- Fast and stable.
- Component tests:
- Render a component and interact with it like a user.
- Assert visible behavior, not implementation details.
- Integration tests:
- Verify components, routing, API clients, and state management work together.
- Mock network at the boundary.
- End-to-end tests:
- Cover critical user journeys: login, search, save, dashboard workflows.
- Fewer tests, high confidence, run in CI and before releases.
- Accessibility:
- Add automated checks for labels, roles, contrast, keyboard flow where possible.
- Manually test important keyboard interactions.
Mocking strategy:
- Mock unstable external services.
- Prefer realistic fixtures and MSW-style request mocks over mocking every function.
What not to over-test:
- CSS implementation details.
- Framework internals.
- Snapshots that change often and catch little.
Good answer: "I want many cheap tests around logic, focused component tests around UI behavior, and a small number of E2E tests around business-critical flows."
Source: Tenable frontend job description