Test pyramid của Mike Cohn: base là nhiều unit tests (nhanh <1ms, rẻ, isolated, dễ maintain), giữa là integration tests (test interaction giữa components/services với real dependencies), đỉnh là ít E2E tests (chậm, đắt, brittle — dễ fail vì network, timing, UI changes).
- Lý do balance 70/20/10: unit tests cho fast feedback và precise error location; integration tests catch boundary bugs unit tests miss; E2E tests verify user journeys nhưng cost cao.
- Ice cream cone anti-pattern (inverted pyramid): nhiều E2E, ít unit — CI chạy chậm, flaky tests, khó debug khi fail.
- Testing Trophy (Kent C.
- Dodds): variation với nhiều integration tests hơn pyramid — 'integration tests give the most confidence per dollar of test cost'.
- Service layer testing: test business logic through service/use-case layer với real database (integration) thay vì mock everything — catches more real bugs.
- Practical: không nên có ratio cứng nhắc, phụ thuộc vào project.
- Smoke tests: minimal E2E tests chạy sau mỗi deployment để verify critical paths hoạt động.
- Contract tests thay E2E trong microservices.
- Key insight: fast tests chạy thường xuyên → fast feedback → catch bugs sớm; slow E2E tests chạy ít hơn → feedback chậm.
Mike Cohn's test pyramid: the base is many unit tests (fast < 1 ms, cheap, isolated, easy to maintain); the middle is integration tests (test interactions between components/services with real dependencies); the apex is few E2E tests (slow, expensive, brittle — easily broken by network issues, timing, or UI changes).
- Reasons for the 70/20/10 balance: unit tests provide fast feedback and precise error location; integration tests catch boundary bugs that unit tests miss; E2E tests verify user journeys but at high cost.
- Ice cream cone anti-pattern (inverted pyramid): many E2E, few unit tests — CI runs slowly, tests are flaky, failures are hard to debug.
- Testing Trophy (Kent C.
- Dodds): a variation with more integration tests than the pyramid — 'integration tests give the most confidence per dollar of test cost.' Service-layer testing: test business logic through the service/use-case layer with a real database (integration) instead of mocking everything — catches more real-world bugs.
- In practice: do not apply ratios rigidly; it depends on the project.
- Smoke tests: minimal E2E tests run after each deployment to verify critical paths work.
- Contract tests replace E2E tests in microservices.
- Key insight: fast tests run frequently → fast feedback → bugs caught early; slow E2E tests run less often → slower feedback.