Test Coverage
Analyze test coverage, identify gaps, and generate missing tests to reach 80%+ coverage.
Step 1: Detect Test Framework
| Indicator |
Coverage Command |
jest.config.* or package.json jest |
npx jest --coverage --coverageReporters=json-summary |
vitest.config.* |
npx vitest run --coverage |
pytest.ini / pyproject.toml pytest |
pytest --cov=src --cov-report=json |
Cargo.toml |
cargo llvm-cov --json |
pom.xml with JaCoCo |
mvn test jacoco:report |
go.mod |
go test -coverprofile=coverage.out ./... |
Step 2: Analyze Coverage Report
- Run the coverage command
- Parse the output (JSON summary or terminal output)
- List files below 80% coverage, sorted worst-first
- For each under-covered file, identify:
- Untested functions or methods
- Missing branch coverage (if/else, switch, error paths)
- Dead code that inflates the denominator
Step 3: Generate Missing Tests
For each under-covered file, generate tests following this priority:
- Happy path — Core functionality with valid inputs
- Error handling — Invalid inputs, missing data, network failures
- Edge cases — Empty arrays, null/undefined, boundary values (0, -1, MAX_INT)
- Branch coverage — Each if/else, switch case, ternary
Test Generation Rules
- Place tests adjacent to source:
foo.ts → foo.test.ts (or project convention)
- Use existing test patterns from the project (import style, assertion library, mocking approach)
- Mock external dependencies (database, APIs, file system)
- Each test should be independent — no shared mutable state between tests
- Name tests descriptively:
test_create_user_with_duplicate_email_returns_409
Step 4: Verify
- Run the full test suite — all tests must pass
- Re-run coverage — verify improvement
- If still below 80%, repeat Step 3 for remaining gaps
Step 5: Report
Show before/after comparison:
Coverage Report
──────────────────────────────
File Before After
src/services/auth.ts 45% 88%
src/utils/validation.ts 32% 82%
──────────────────────────────
Overall: 67% 84% PASS:
Focus Areas
- Functions with complex branching (high cyclomatic complexity)
- Error handlers and catch blocks
- Utility functions used across the codebase
- API endpoint handlers (request → response flow)
- Edge cases: null, undefined, empty string, empty array, zero, negative numbers
1---2name: test-coverage3description: Analyzes test coverage reports, identifies under-covered files, and generates missing tests to reach 80% or higher coverage.4---56# Test Coverage78Analyze test coverage, identify gaps, and generate missing tests to reach 80%+ coverage.910## Step 1: Detect Test Framework1112| Indicator | Coverage Command |13|-----------|-----------------|14| `jest.config.*` or `package.json` jest | `npx jest --coverage --coverageReporters=json-summary` |15| `vitest.config.*` | `npx vitest run --coverage` |16| `pytest.ini` / `pyproject.toml` pytest | `pytest --cov=src --cov-report=json` |17| `Cargo.toml` | `cargo llvm-cov --json` |18| `pom.xml` with JaCoCo | `mvn test jacoco:report` |19| `go.mod` | `go test -coverprofile=coverage.out ./...` |2021## Step 2: Analyze Coverage Report22231. Run the coverage command242. Parse the output (JSON summary or terminal output)253. List files **below 80% coverage**, sorted worst-first264. For each under-covered file, identify:27 - Untested functions or methods28 - Missing branch coverage (if/else, switch, error paths)29 - Dead code that inflates the denominator3031## Step 3: Generate Missing Tests3233For each under-covered file, generate tests following this priority:34351. **Happy path** — Core functionality with valid inputs362. **Error handling** — Invalid inputs, missing data, network failures373. **Edge cases** — Empty arrays, null/undefined, boundary values (0, -1, MAX_INT)384. **Branch coverage** — Each if/else, switch case, ternary3940### Test Generation Rules4142- Place tests adjacent to source: `foo.ts` → `foo.test.ts` (or project convention)43- Use existing test patterns from the project (import style, assertion library, mocking approach)44- Mock external dependencies (database, APIs, file system)45- Each test should be independent — no shared mutable state between tests46- Name tests descriptively: `test_create_user_with_duplicate_email_returns_409`4748## Step 4: Verify49501. Run the full test suite — all tests must pass512. Re-run coverage — verify improvement523. If still below 80%, repeat Step 3 for remaining gaps5354## Step 5: Report5556Show before/after comparison:5758```59Coverage Report60──────────────────────────────61File Before After62src/services/auth.ts 45% 88%63src/utils/validation.ts 32% 82%64──────────────────────────────65Overall: 67% 84% PASS:66```6768## Focus Areas6970- Functions with complex branching (high cyclomatic complexity)71- Error handlers and catch blocks72- Utility functions used across the codebase73- API endpoint handlers (request → response flow)74- Edge cases: null, undefined, empty string, empty array, zero, negative numbers