What's the difference between end-to-end (E2E) tests and unit tests, and when do you use each?
Short answer
E2E tests (e.g. Playwright, Cypress) drive a real browser through actual user flows across the whole app, catching integration issues unit tests can't — but they're slower and more brittle.
Advertisement
AModel answer
E2E tests (e.g. Playwright, Cypress) drive a real browser through actual user flows across the whole app, catching integration issues unit tests can't — but they're slower and more brittle. Unit tests are fast and precise but can't catch issues that only appear when pieces are wired together.
// Playwright E2E example
await page.goto('/login');
await page.fill('#email', 'test@example.com');
await page.click('#submit');
await expect(page).toHaveURL('/dashboard');Real-world example
Using unit tests for a validation function, but an E2E test for the full checkout flow across multiple pages.
Likely follow-ups
- What's the 'testing pyramid' and why do most teams have far more unit tests than E2E tests?
Related topics