Unit tests
Fast tests of a single function or component in isolation.
Jest or Vitest with React Testing Library; many of them, run on every change.
Testing
Unit tests check one piece in isolation, integration tests check pieces working together, and end-to-end tests drive the real app in a browser the way a user would.
Fast tests of a single function or component in isolation.
Jest or Vitest with React Testing Library; many of them, run on every change.
Tests of several units together, such as a component with its data layer.
Catch wiring mistakes that unit tests miss; mock only external services.
Tests that drive the full application in a real browser.
Playwright or Cypress; slowest and fewest, covering critical user journeys.
| Aspect | Unit tests | Integration tests | End-to-end tests |
|---|---|---|---|
| Scope | One unit | Several units | Whole app |
| Speed | Milliseconds | Seconds | Seconds to minutes |
| How many | Most | Some | Fewest |
| Tools | Jest, Vitest | Vitest + RTL, Supertest | Playwright, Cypress |
| Catches | Logic bugs | Wiring bugs | Broken user journeys |
Unit tests check one function or component in isolation. Integration tests check several units working together, such as a component with its data layer or an API with its database. End-to-end tests drive the whole running application through a real browser as a user would.
A guideline to have many fast unit tests, fewer integration tests and a small number of slow end-to-end tests, balancing confidence, speed and maintenance cost.
A model popularised for front-end apps that puts the biggest share in integration tests, plus static analysis at the base, because integration tests give high confidence at reasonable cost.
Unit: Vitest or Jest. Integration: Vitest or Jest with React Testing Library, Supertest for APIs, or a test database. End-to-end: Playwright or Cypress against the running app.
End-to-end tests are slow, more fragile and harder to debug, so a large suite delays feedback. Most behaviour is checked faster and more precisely at lower levels.
Pure logic with clear inputs and outputs: calculations, validation rules, formatting, reducers and edge cases such as empty or extreme values.
Wiring between parts: a form submitting through a hook to a mocked API, a route handler writing to a test database, or several modules coordinating.
Critical user journeys: sign-up and login, checkout or payment, core creation flows and anything where a failure would hurt users or revenue.
Unit tests mock collaborators freely. Integration tests mock only external services such as payment providers. End-to-end tests mock as little as possible, sometimes only third parties.
Unit tests run in milliseconds, integration tests in tens of milliseconds to seconds, and end-to-end tests in seconds to minutes each.
Practise every comparison in your dashboard.
Start learning