Testing Strategies (Unit, Integration, E2E)
Testing Strategies (Unit, Integration, E2E)
Overview
Tests give you confidence to change code. Aim for a balanced pyramid: many unit tests, some integration tests, a few E2E tests.
Types
- Unit: test one function or component in isolation
- Integration: test how modules talk to each other (e.g., API + DB)
- E2E: test key user flows in a running app (e.g., Playwright, Cypress)
Example
- Unit: formatPrice()
- Integration: POST /api/tasks creates a task in DB
- E2E: user logs in and creates a task through the UI
Checklist
- Add test runner and coverage in CI
- Seed data for integration tests
- Make E2E tests flaky-resistant (wait for selectors)
Resources
- Jest, Vitest
- Playwright.dev, Cypress.io
- Testing Library: testing-library.com