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-coverage3metadata:4 source: https://skillmd.com/skills/auto-skiller/test-coverage5 name: test-coverage6 class: toolboxes7 type: skill8 version: '1.0'9 schema_version: '1.0'10 freshness:11 status: active12 sync_count: 013 last_synced_by: daemon14 last_synced: '2026-06-27T00:00:00'15credentials:16 maturity: "functional"17 description: "Skill for Test Coverage"18 when_to_use: "fg"19 triggers: []20 inputs: []21 outputs: []22---2324# Test Coverage2526Analyze test coverage, identify gaps, and generate missing tests to reach 80%+ coverage.2728## Step 1: Detect Test Framework2930| Indicator | Coverage Command |31|-----------|-----------------|32| `jest.config.*` or `package.json` jest | `npx jest --coverage --coverageReporters=json-summary` |33| `vitest.config.*` | `npx vitest run --coverage` |34| `pytest.ini` / `pyproject.toml` pytest | `pytest --cov=src --cov-report=json` |35| `Cargo.toml` | `cargo llvm-cov --json` |36| `pom.xml` with JaCoCo | `mvn test jacoco:report` |37| `go.mod` | `go test -coverprofile=coverage.out ./...` |3839## Step 2: Analyze Coverage Report40411. Run the coverage command422. Parse the output (JSON summary or terminal output)433. List files **below 80% coverage**, sorted worst-first444. For each under-covered file, identify:45 - Untested functions or methods46 - Missing branch coverage (if/else, switch, error paths)47 - Dead code that inflates the denominator4849## Step 3: Generate Missing Tests5051For each under-covered file, generate tests following this priority:52531. **Happy path** — Core functionality with valid inputs542. **Error handling** — Invalid inputs, missing data, network failures553. **Edge cases** — Empty arrays, null/undefined, boundary values (0, -1, MAX_INT)564. **Branch coverage** — Each if/else, switch case, ternary5758### Test Generation Rules5960- Place tests adjacent to source: `foo.ts` → `foo.test.ts` (or project convention)61- Use existing test patterns from the project (import style, assertion library, mocking approach)62- Mock external dependencies (database, APIs, file system)63- Each test should be independent — no shared mutable state between tests64- Name tests descriptively: `test_create_user_with_duplicate_email_returns_409`6566## Step 4: Verify67681. Run the full test suite — all tests must pass692. Re-run coverage — verify improvement703. If still below 80%, repeat Step 3 for remaining gaps7172## Step 5: Report7374Show before/after comparison:7576```77Coverage Report78──────────────────────────────79File Before After80src/services/auth.ts 45% 88%81src/utils/validation.ts 32% 82%82──────────────────────────────83Overall: 67% 84% PASS:84```8586## Focus Areas8788- Functions with complex branching (high cyclomatic complexity)89- Error handlers and catch blocks90- Utility functions used across the codebase91- API endpoint handlers (request → response flow)92- Edge cases: null, undefined, empty string, empty array, zero, negative numbers