# Test Strategy — Quick Reference

## Test Pyramid

| Layer | What It Tests | Speed | Count |
|-------|---------------|-------|-------|
| **Unit** | Single function/class in isolation | Fast (ms) | Many |
| **Integration** | Components + DB/API/services | Medium | Some |
| **E2E** | Full user journey (UI → backend) | Slow (min) | Few |

**Rule:** Many unit, some integration, few e2e.

## What to Test

| Focus | Examples |
|-------|----------|
| **Happy path** | Valid input → expected output |
| **Edge cases** | Empty list, boundary values, max length |
| **Error paths** | Invalid input, network failure, permission denied |
| **Contracts** | API shape, component props |

## What NOT to Test

- **Implementation details** — Internal state, hook call counts
- **Third-party code** — Trust libraries; mock if needed
- **Trivial code** — Getters/setters with no logic
- **Everything** — Prioritize risk; diminishing returns

## Test Doubles

| Type | Purpose |
|------|---------|
| **Stub** | Returns canned data; no verification |
| **Mock** | Verifies it was called (expectations) |
| **Spy** | Records calls; assert after |

**When stub:** You only need a fake response.  
**When mock:** You need to verify the collaborator was used correctly.

## CI/CD Order

```
Commit → Unit (fast) → Integration → E2E → Deploy
```

- Unit + integration: every PR
- E2E: merge to main or nightly (optional per-PR)

## Coverage

- **Use:** Find gaps in critical paths
- **Don't:** Aim for 100%; avoid testing for coverage's sake
- **Meaningful coverage:** Assert behavior, not just "didn't throw"

## Diamond/Trophy Shape

Some teams invert the pyramid: more integration than unit. Use when business logic lives in integration layers. Test what matters, where it matters.

## Quick Checklist

- [ ] Unit tests for logic, validation, edge cases
- [ ] Integration tests for DB, API, services
- [ ] E2E for critical user flows (few)
- [ ] Stub/mock external dependencies in unit tests
- [ ] Avoid asserting on implementation details
- [ ] Run fast tests first in CI
