Testing
The Testing Pyramid
The testing pyramid is a concept that helps guide how many tests of each type you should write:
text
/\
/ \ ← UI Tests (Few, Slow, High-level)
/────\
/ \ ← Integration Tests (Some, Medium speed)
/────────\
/ \ ← Unit Tests (Many, Fast, Low-level)
/────────────\Recommended distribution:
- 70% Unit tests - Fast, isolated, test individual functions/methods
- 20% Integration tests - Test components working together
- 10% UI tests - Test critical user journeys end-to-end
Why this ratio?
- Unit tests are fast and catch most bugs early
- Too many UI tests = slow test suite and high maintenance
- UI tests focus on critical paths, not every edge case
Comparison of test types
| Aspect | Unit Tests | Integration Tests | UI Tests |
|---|---|---|---|
| Scope | Single function/method | Multiple components | Entire application |
| Speed | ⚡⚡⚡ Very fast | ⚡⚡ Fast | 🐌 Slow |
| Reliability | ✅ Very stable | ✅ Stable | ⚠️ Can be flaky |
| Maintenance | ✅ Low | 🟡 Medium | ⚠️ High |
| Debugging | ✅ Easy | 🟡 Medium | ⚠️ Difficult |
| Coverage | Detailed | Moderate | High-level |
| When to use | Always, many | For integrations | Critical paths only |
| Example | add(2, 3) === 5 | API + DB test | Full checkout flow |
Further information
Link: UI Tests
