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-strategy3department: "craftsman"4description: "Design comprehensive test strategies with test pyramid coverage and quality gates"5version: 16triggers:7 - "test"8 - "testing"9 - "unit test"10 - "integration test"11 - "e2e"12 - "coverage"13 - "CI"14 - "quality gate"15 - "regression"16 - "TDD"17---1819# Testing Strategy2021## Purpose2223Design comprehensive test strategies with test pyramid coverage, test file structure, and quality gates.2425## Inputs2627- Feature description and scope28- Existing test infrastructure (framework, runner, coverage tools)29- CI/CD pipeline details (if relevant)30- Existing test conventions in the codebase31- Coverage targets or requirements (if any)3233## Process3435### Step 1: Audit Existing Test Infrastructure3637- Test framework (Jest, Vitest, Playwright, Cypress, etc.)38- Test runner and configuration39- Coverage tools (Istanbul, c8, etc.)40- CI integration (GitHub Actions, etc.)41- Existing test patterns (file location, naming, describe/it structure)42- Existing mocking patterns (jest.mock, vi.mock, MSW, etc.)4344### Step 2: Identify Testable Units4546From the feature, extract:47- **Pure functions and utilities** — deterministic, no side effects, easiest to test48- **Data transformations** — input/output mapping, validation logic49- **API handlers/endpoints** — request/response contracts, error handling50- **UI components** — render output, interaction behavior, state changes51- **Integration points** — database queries, external API calls, file I/O52- **Business logic** — rules, calculations, conditional flows5354### Step 3: Design the Test Pyramid5556```57 / E2E \ ← Few: critical user paths only (expensive, slow)58 /----------\59 / Integration \ ← Some: cross-boundary, API contracts, DB queries60 /----------------\61 / Unit Tests \ ← Many: fast, isolated, 80%+ of test count62 /--------------------\63```6465- **Unit tests (base):** Fast, isolated, test one thing. Target 80%+ of total test count.66- **Integration tests (middle):** Cross-boundary tests. Database interactions, API contracts, service-to-service.67- **E2E tests (top):** Critical user paths only. Expensive to write and maintain, keep count low.6869### Step 4: Write Test Specifications7071For each layer, specify:7273| Layer | Test File | Test Cases | Mocks Needed | Priority |74|-------|-----------|------------|--------------|----------|75| Unit | ... | ... | ... | ... |76| Integration | ... | ... | ... | ... |77| E2E | ... | ... | ... | ... |7879For each test case:80- **Location:** Follow existing convention (co-located `__tests__/`, top-level `tests/`, or `.test.ts` suffix)81- **Description:** `describe('ModuleName', () => { it('should ...') })` format82- **Key assertions:** What exactly are we verifying?83- **Mock strategy:** What to mock (external deps), what to keep real (internal logic)84- **Edge cases:** Boundary values, empty inputs, error conditions8586### Step 5: Define Coverage Targets8788- **Line coverage:** Pragmatic target (70-90%, not 100%)89- **Branch coverage:** Focus on critical paths and business logic branches90- **Not worth testing:** Glue code, framework boilerplate, simple pass-through, type-only files91- **Must test:** Business rules, data transformations, error handling, security-sensitive code9293### Step 6: Plan Quality Gates9495- **Pre-commit:**96 - Lint (ESLint, Biome)97 - Type check (tsc --noEmit)98 - Affected unit tests (if tooling supports)99- **CI pipeline:**100 - Full test suite101 - Coverage threshold check102 - Build verification103- **Manual review checklist:**104 - [ ] New business logic has unit tests105 - [ ] Error paths are tested106 - [ ] No snapshot tests for logic (only for stable UI)107 - [ ] Mocks don't hide real bugs108 - [ ] Test descriptions read as documentation109110## Output Format111112### Test Pyramid Summary113114| Layer | Count | Run Time | Mock Strategy |115|-------|-------|----------|---------------|116| Unit | ... | ... | ... |117| Integration | ... | ... | ... |118| E2E | ... | ... | ... |119120### Test Specifications121122For each test file:123124```125File: src/__tests__/feature.test.ts126Layer: Unit127128describe('FeatureName')129 it('should handle the happy path')130 - Input: ...131 - Expected: ...132 it('should handle invalid input')133 - Input: ...134 - Expected: throws/returns error135 it('should handle edge case')136 - Input: ...137 - Expected: ...138139Mocks: ExternalService (return mock data)140```141142### Coverage Targets143144| Category | Target | Rationale |145|----------|--------|-----------|146| Business logic | 90%+ | Core value, must be correct |147| API handlers | 80%+ | Contract compliance |148| UI components | 70%+ | Render + key interactions |149| Utilities | 90%+ | Pure functions, easy to test |150| Glue/config | Skip | Not worth testing |151152### Quality Gate Checklist153154- [ ] Pre-commit hooks configured155- [ ] CI runs full test suite156- [ ] Coverage thresholds enforced157- [ ] New code has corresponding tests158159## Quality Checks160161- [ ] Every business logic function has a unit test spec162- [ ] Critical user paths have integration tests163- [ ] At least 1 E2E test for the main happy-path flow164- [ ] Mock strategy documented and doesn't hide real bugs165- [ ] Test file locations follow existing project conventions166- [ ] Edge cases and error paths included in test specs167- [ ] Coverage targets are pragmatic (not aspirational 100%)168169## Evolution Notes170<!-- Observations appended after each use -->