Test Coverage Analysis
Source: affaan-m/everything-claude-code Original files: commands/test-coverage.md, rules/common/testing.md Curated: 2026-02-21
Minimum Coverage: 80%
All three test types are required:
- Unit Tests -- Individual functions, utilities, components
- Integration Tests -- API endpoints, database operations
- E2E Tests -- Critical user flows
Framework Detection
| 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 ./... |
Workflow
Step 1: Analyze Coverage
- Run the coverage command
- Parse output (JSON summary or terminal)
- List files below 80%, sorted worst-first
- For each under-covered file, identify untested functions, missing branches, and dead code
Step 2: Generate Tests
Priority order:
- Happy path -- Core functionality with valid inputs
- Error handling -- Invalid inputs, missing data, failures
- Edge cases -- Empty arrays, null/undefined, boundary values
- Branch coverage -- Each if/else, switch, ternary
Rules:
- Place tests adjacent to source (
foo.ts->foo.test.ts) - Match existing project patterns
- Mock external dependencies
- Each test must be independent
- Use descriptive names:
test_create_user_with_duplicate_email_returns_409
Step 3: Verify
- Run full test suite -- all must pass
- Re-run coverage -- verify improvement
- Repeat if still below 80%
Step 4: Report
Coverage Report
------------------------------
File Before After
src/services/auth.ts 45% 88%
src/utils/validation.ts 32% 82%
------------------------------
Overall: 67% 84%
TDD Workflow (Mandatory)
- Write test first (RED)
- Run test -- should FAIL
- Write minimal implementation (GREEN)
- Run test -- should PASS
- Refactor (IMPROVE)
- Verify coverage (80%+)
Focus Areas
- High cyclomatic complexity functions
- Error handlers and catch blocks
- Utility functions used across the codebase
- API endpoint handlers
- Edge cases: null, undefined, empty string, empty array, zero, negative numbers
Troubleshooting
- Use the tdd-guide agent
- Check test isolation
- Verify mocks are correct
- Fix implementation, not tests (unless tests are wrong)