Test Coverage Analyzer
Analyze test coverage and generate tests to fill gaps.
Workflow
- •
Run coverage analysis:
- •Detect the test framework and run with coverage enabled:
- •JS/TS:
npx jest --coverageornpx vitest --coverageornpx nyc mocha - •Python:
pytest --cov=<package> --cov-report=term-missing - •Go:
go test -coverprofile=coverage.out ./... && go tool cover -func=coverage.out - •Rust:
cargo tarpaulinorcargo llvm-cov
- •JS/TS:
- •Parse the coverage output.
- •Detect the test framework and run with coverage enabled:
- •
Analyze coverage gaps:
- •Identify files with lowest coverage.
- •Identify uncovered lines and branches.
- •Categorize gaps:
- •Critical: Business logic, data validation, security checks.
- •Important: Error handling, edge cases.
- •Low priority: Logging, formatting, simple getters/setters.
- •
Present a coverage report:
code
Coverage Summary: XX.X% (target: YY%) Critical Gaps: src/auth/login.ts 45% — lines 23-40, 67-89 (authentication logic) src/api/payments.ts 38% — lines 12-35 (payment processing) Important Gaps: src/utils/validator.ts 62% — lines 44-58 (error handling) Files at 100%: 12/30
- •
Generate tests for the highest-priority gaps:
- •Start with critical business logic.
- •Focus on untested branches and error paths.
- •Follow the project's existing test patterns.
- •
Re-run coverage to verify improvement.
Guidelines
- •Focus on meaningful coverage, not just hitting a number.
- •100% coverage doesn't mean bug-free — test quality matters more than quantity.
- •Prioritize branch coverage over line coverage.
- •Don't test trivially obvious code just for the coverage number.
- •If coverage tooling isn't set up, help configure it first.
- •Consider setting up coverage thresholds in CI config if not already present.