Testing Strategy
Purpose
Design comprehensive test strategies with test pyramid coverage, test file structure, and quality gates.
Inputs
- Feature description and scope
- Existing test infrastructure (framework, runner, coverage tools)
- CI/CD pipeline details (if relevant)
- Existing test conventions in the codebase
- Coverage targets or requirements (if any)
Process
Step 1: Audit Existing Test Infrastructure
- Test framework (Jest, Vitest, Playwright, Cypress, etc.)
- Test runner and configuration
- Coverage tools (Istanbul, c8, etc.)
- CI integration (GitHub Actions, etc.)
- Existing test patterns (file location, naming, describe/it structure)
- Existing mocking patterns (jest.mock, vi.mock, MSW, etc.)
Step 2: Identify Testable Units
From the feature, extract:
- Pure functions and utilities — deterministic, no side effects, easiest to test
- Data transformations — input/output mapping, validation logic
- API handlers/endpoints — request/response contracts, error handling
- UI components — render output, interaction behavior, state changes
- Integration points — database queries, external API calls, file I/O
- Business logic — rules, calculations, conditional flows
Step 3: Design the Test Pyramid
/ E2E \ ← Few: critical user paths only (expensive, slow)
/----------\
/ Integration \ ← Some: cross-boundary, API contracts, DB queries
/----------------\
/ Unit Tests \ ← Many: fast, isolated, 80%+ of test count
/--------------------\
- Unit tests (base): Fast, isolated, test one thing. Target 80%+ of total test count.
- Integration tests (middle): Cross-boundary tests. Database interactions, API contracts, service-to-service.
- E2E tests (top): Critical user paths only. Expensive to write and maintain, keep count low.
Step 4: Write Test Specifications
For each layer, specify:
| Layer |
Test File |
Test Cases |
Mocks Needed |
Priority |
| Unit |
... |
... |
... |
... |
| Integration |
... |
... |
... |
... |
| E2E |
... |
... |
... |
... |
For each test case:
- Location: Follow existing convention (co-located
__tests__/, top-level tests/, or .test.ts suffix)
- Description:
describe('ModuleName', () => { it('should ...') }) format
- Key assertions: What exactly are we verifying?
- Mock strategy: What to mock (external deps), what to keep real (internal logic)
- Edge cases: Boundary values, empty inputs, error conditions
Step 5: Define Coverage Targets
- Line coverage: Pragmatic target (70-90%, not 100%)
- Branch coverage: Focus on critical paths and business logic branches
- Not worth testing: Glue code, framework boilerplate, simple pass-through, type-only files
- Must test: Business rules, data transformations, error handling, security-sensitive code
Step 6: Plan Quality Gates
- Pre-commit:
- Lint (ESLint, Biome)
- Type check (tsc --noEmit)
- Affected unit tests (if tooling supports)
- CI pipeline:
- Full test suite
- Coverage threshold check
- Build verification
- Manual review checklist:
Output Format
Test Pyramid Summary
| Layer |
Count |
Run Time |
Mock Strategy |
| Unit |
... |
... |
... |
| Integration |
... |
... |
... |
| E2E |
... |
... |
... |
Test Specifications
For each test file:
File: src/__tests__/feature.test.ts
Layer: Unit
describe('FeatureName')
it('should handle the happy path')
- Input: ...
- Expected: ...
it('should handle invalid input')
- Input: ...
- Expected: throws/returns error
it('should handle edge case')
- Input: ...
- Expected: ...
Mocks: ExternalService (return mock data)
Coverage Targets
| Category |
Target |
Rationale |
| Business logic |
90%+ |
Core value, must be correct |
| API handlers |
80%+ |
Contract compliance |
| UI components |
70%+ |
Render + key interactions |
| Utilities |
90%+ |
Pure functions, easy to test |
| Glue/config |
Skip |
Not worth testing |
Quality Gate Checklist
Quality Checks
Evolution Notes
1---2name: testing-strategy3description: Design comprehensive test strategies with test pyramid coverage and quality gates4---56# Testing Strategy78## Purpose910Design comprehensive test strategies with test pyramid coverage, test file structure, and quality gates.1112## Inputs1314- Feature description and scope15- Existing test infrastructure (framework, runner, coverage tools)16- CI/CD pipeline details (if relevant)17- Existing test conventions in the codebase18- Coverage targets or requirements (if any)1920## Process2122### Step 1: Audit Existing Test Infrastructure2324- Test framework (Jest, Vitest, Playwright, Cypress, etc.)25- Test runner and configuration26- Coverage tools (Istanbul, c8, etc.)27- CI integration (GitHub Actions, etc.)28- Existing test patterns (file location, naming, describe/it structure)29- Existing mocking patterns (jest.mock, vi.mock, MSW, etc.)3031### Step 2: Identify Testable Units3233From the feature, extract:34- **Pure functions and utilities** — deterministic, no side effects, easiest to test35- **Data transformations** — input/output mapping, validation logic36- **API handlers/endpoints** — request/response contracts, error handling37- **UI components** — render output, interaction behavior, state changes38- **Integration points** — database queries, external API calls, file I/O39- **Business logic** — rules, calculations, conditional flows4041### Step 3: Design the Test Pyramid4243```44 / E2E \ ← Few: critical user paths only (expensive, slow)45 /----------\46 / Integration \ ← Some: cross-boundary, API contracts, DB queries47 /----------------\48 / Unit Tests \ ← Many: fast, isolated, 80%+ of test count49 /--------------------\50```5152- **Unit tests (base):** Fast, isolated, test one thing. Target 80%+ of total test count.53- **Integration tests (middle):** Cross-boundary tests. Database interactions, API contracts, service-to-service.54- **E2E tests (top):** Critical user paths only. Expensive to write and maintain, keep count low.5556### Step 4: Write Test Specifications5758For each layer, specify:5960| Layer | Test File | Test Cases | Mocks Needed | Priority |61|-------|-----------|------------|--------------|----------|62| Unit | ... | ... | ... | ... |63| Integration | ... | ... | ... | ... |64| E2E | ... | ... | ... | ... |6566For each test case:67- **Location:** Follow existing convention (co-located `__tests__/`, top-level `tests/`, or `.test.ts` suffix)68- **Description:** `describe('ModuleName', () => { it('should ...') })` format69- **Key assertions:** What exactly are we verifying?70- **Mock strategy:** What to mock (external deps), what to keep real (internal logic)71- **Edge cases:** Boundary values, empty inputs, error conditions7273### Step 5: Define Coverage Targets7475- **Line coverage:** Pragmatic target (70-90%, not 100%)76- **Branch coverage:** Focus on critical paths and business logic branches77- **Not worth testing:** Glue code, framework boilerplate, simple pass-through, type-only files78- **Must test:** Business rules, data transformations, error handling, security-sensitive code7980### Step 6: Plan Quality Gates8182- **Pre-commit:**83 - Lint (ESLint, Biome)84 - Type check (tsc --noEmit)85 - Affected unit tests (if tooling supports)86- **CI pipeline:**87 - Full test suite88 - Coverage threshold check89 - Build verification90- **Manual review checklist:**91 - [ ] New business logic has unit tests92 - [ ] Error paths are tested93 - [ ] No snapshot tests for logic (only for stable UI)94 - [ ] Mocks don't hide real bugs95 - [ ] Test descriptions read as documentation9697## Output Format9899### Test Pyramid Summary100101| Layer | Count | Run Time | Mock Strategy |102|-------|-------|----------|---------------|103| Unit | ... | ... | ... |104| Integration | ... | ... | ... |105| E2E | ... | ... | ... |106107### Test Specifications108109For each test file:110111```112File: src/__tests__/feature.test.ts113Layer: Unit114115describe('FeatureName')116 it('should handle the happy path')117 - Input: ...118 - Expected: ...119 it('should handle invalid input')120 - Input: ...121 - Expected: throws/returns error122 it('should handle edge case')123 - Input: ...124 - Expected: ...125126Mocks: ExternalService (return mock data)127```128129### Coverage Targets130131| Category | Target | Rationale |132|----------|--------|-----------|133| Business logic | 90%+ | Core value, must be correct |134| API handlers | 80%+ | Contract compliance |135| UI components | 70%+ | Render + key interactions |136| Utilities | 90%+ | Pure functions, easy to test |137| Glue/config | Skip | Not worth testing |138139### Quality Gate Checklist140141- [ ] Pre-commit hooks configured142- [ ] CI runs full test suite143- [ ] Coverage thresholds enforced144- [ ] New code has corresponding tests145146## Quality Checks147148- [ ] Every business logic function has a unit test spec149- [ ] Critical user paths have integration tests150- [ ] At least 1 E2E test for the main happy-path flow151- [ ] Mock strategy documented and doesn't hide real bugs152- [ ] Test file locations follow existing project conventions153- [ ] Edge cases and error paths included in test specs154- [ ] Coverage targets are pragmatic (not aspirational 100%)155156## Evolution Notes157<!-- Observations appended after each use -->