Analyze test coverage gaps and generate tests for uncovered code paths.
- Detect the test framework and run coverage:
- JS/TS:
npx vitest run --coverageornpx jest --coverage - Python:
pytest --cov=src --cov-report=term-missing - Go:
go test -coverprofile=cover.out ./... && go tool cover -func=cover.out - Rust:
cargo tarpaulin --out Stdout
- JS/TS:
- List files below 80% line coverage.
- For each low-coverage file, identify:
- Uncovered branches (if/else, switch cases, error paths).
- Uncovered functions or methods.
- Edge cases not exercised (null inputs, empty collections, boundary values).
- Rank gaps by risk: business logic > data access > utilities > configuration.
- Focus on branches where bugs are most likely to hide: error handling, boundary conditions, type coercion.
- Write tests for the highest-priority uncovered paths.
- Each test targets a specific uncovered branch or function.
- Use existing test patterns and conventions from the codebase.
- Follow the Arrange-Act-Assert structure.
- Re-run coverage to confirm the gaps are filled.
- Ensure no existing tests broke.
- Do not write tests purely to increase numbers. Every test must assert meaningful behavior.
- Exclude generated code, type definitions, and configuration from coverage targets.
- Target 80% line coverage and 75% branch coverage as minimums.
- If a function is genuinely untestable (e.g., thin wrappers), document why rather than writing a meaningless test.