Smart Test Coverage
Boost productivity using this analyze, improve, test, coverage. Includes structured workflows, validation checks, and reusable patterns for testing.
Smart Test Coverage
Analyze test coverage across your codebase, identify uncovered files and functions, and generate a prioritized list of what to test next.
When to Use This Command
Run this command when...
- You want to see which parts of your codebase lack test coverage
- You need to prioritize writing tests for the most critical uncovered code paths
- You are preparing a coverage report for a code review or sprint planning session
Avoid this command when...
- You just need to run existing tests without coverage analysis
- Your project already has coverage thresholds enforced in CI and you only need pass/fail
Quick Start
# .claude/commands/smart-test-coverage.md --- allowed-tools: ["Bash", "Read", "Grep"] --- Run test coverage analysis. Identify uncovered files, functions, and branches. Prioritize by complexity and change frequency.
Example usage:
/smart-test-coverage src/
Example output:
Overall Coverage: 73.2% (target: 80%)
Uncovered Files (by priority):
1. src/services/payment.ts 12 uncovered functions HIGH
2. src/utils/validators.ts 8 uncovered branches MED
3. src/helpers/format.ts 3 uncovered lines LOW
Recommendation: Start with payment.ts (highest complexity)
Core Concepts
| Concept | Description |
|---|---|
| Line coverage | Percentage of executable lines hit during tests |
| Branch coverage | Whether both true/false paths of conditionals are tested |
| Function coverage | Whether each function has been called at least once |
| Priority score | Combines complexity, change frequency, and criticality |
Source Files ---> Coverage Tool ---> Raw Report
|
+---------+---------+
| | |
Lines Branches Functions
\ | /
+--- Priority ---+
|
Ranked Recommendations
Configuration
| Option | Default | Description |
|---|---|---|
threshold | 80 | Target coverage percentage |
format | summary | Output format (summary, detailed, json) |
include | src/ | Directories to include in analysis |
exclude | node_modules,dist | Paths to exclude |
sort-by | priority | Sort uncovered items (priority, name, coverage) |
Best Practices
- Set realistic thresholds -- 80% is a solid target; pushing to 100% often leads to brittle tests of trivial code.
- Focus on branch coverage -- line coverage can be misleading when conditionals are only half-tested.
- Prioritize by risk -- cover payment, auth, and data-mutation code before formatting utilities.
- Track trends over time -- a coverage number matters less than whether it is going up or down.
- Exclude generated code -- auto-generated files inflate or deflate coverage numbers unfairly.
Common Issues
- Coverage tool not found -- Install the appropriate tool:
nycorc8for Node.js,coverage.pyfor Python,go test -coverfor Go. - Unexpectedly low numbers -- Check that test files are not included in the source count and that mocks are not inflating the denominator.
- Slow execution -- Coverage instrumentation adds overhead. Run coverage analysis separately from quick test passes.
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Git Commit Message Generator
Generates well-structured conventional commit messages by analyzing staged changes. Follows Conventional Commits spec with scope detection.
React Component Scaffolder
Scaffolds a complete React component with TypeScript types, Tailwind styles, Storybook stories, and unit tests. Follows project conventions automatically.
CI/CD Pipeline Generator
Generates GitHub Actions workflows for CI/CD including linting, testing, building, and deploying. Detects project stack automatically.