Test pyramid gồm ba tầng:
- Unit test ở đáy — nhiều nhất, chạy nhanh, test từng function hoặc component riêng lẻ bằng Jest hoặc Vitest.
- Integration test ở giữa — test sự tương tác giữa các component hoặc module bằng Testing Library.
- E2E test ở đỉnh — ít nhất, chạy chậm nhất, test toàn bộ luồng người dùng bằng Cypress hoặc Playwright
Chiến lược hợp lý: unit test phủ rộng logic nghiệp vụ, integration test cho các luồng quan trọng, E2E chỉ cho critical path như đăng nhập, thanh toán.
Mục tiêu là có feedback nhanh từ unit test và độ tin cậy cao từ E2E.
The test pyramid has three layers:
- Unit tests at the base — the most numerous, fastest to run, testing individual functions or components with Jest or Vitest.
- Integration tests in the middle — testing interactions between components or modules with Testing Library.
- E2E tests at the top — fewest in number, slowest, testing full user flows with Cypress or Playwright
Sound strategy: unit tests for broad business logic coverage, integration tests for important flows, E2E only for critical paths like login and checkout.
The goal: fast feedback from unit tests and high confidence from E2E.