Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
The test-coverage skill provides comprehensive on-demand test coverage analysis for your codebase. It identifies untested code paths, measures coverage metrics, finds test gaps, evaluates test quality, and provides actionable recommendations for improving test coverage across all supported technology stacks.
Definition: Percentage of executable lines that are executed by tests.
Example:
functiondivide(a: number, b: number): number {
if (b === 0) { // Line 1: COVEREDthrownewError('Div 0'); // Line 2: NOT COVERED
}
return a / b; // Line 3: COVERED
}
// Test only covers normal casetest('divides numbers', () => {
expect(divide(10, 2)).toBe(5);
});
// Line Coverage: 66% (2/3 lines)
Interpretation:
100%: All lines executed (ideal for critical code)
80-99%: Good coverage, some edge cases missed
60-79%: Moderate, needs improvement
<60%: Poor, significant gaps
2. Branch Coverage
Definition: Percentage of decision branches (if/else, switch, ternary) that are tested.
ok github.com/user/project/auth 0.234s coverage: 34.5% of statements
ok github.com/user/project/payments 0.156s coverage: 41.2% of statements
ok github.com/user/project/users 0.189s coverage: 62.3% of statements
## Integration with Dev Plugin
### With Test Architect Agent
Request comprehensive test creation:
Analyze test coverage and generate tests for all critical gaps
The test-architect agent will:
1. Identify gaps using this skill
2. Generate test files
3. Run tests and verify coverage improvement
### With Audit Skill
Combine coverage with security:
Identify untested security-critical code paths
### With Optimize Skill
Balance coverage with performance:
Check test coverage impact on build time
## Best Practices
### 1. Set Coverage Targets by Risk
**Critical Code** (95%+ coverage):
- Authentication and authorization
- Payment processing
- Data validation
- Security checks
**Business Logic** (80%+ coverage):
- Core features
- API endpoints
- State management
**Utilities** (70%+ coverage):
- Helper functions
- Formatters
- Parsers
**Infrastructure** (50%+ coverage):
- Configuration
- Build scripts
- Tooling
### 2. Focus on Untested Branches
Branch coverage > line coverage for finding bugs.
**Example**:
```typescript
// 100% line coverage, 50% branch coverage
function process(data: Data | null) {
const result = data ? data.value : 0; // Both branches needed
return result * 2;
}
// Test only null case - 100% lines, 50% branches
test('handles null', () => {
expect(process(null)).toBe(0);
});
// Need both cases
test('handles data', () => {
expect(process({ value: 5 })).toBe(10);
});
test('displays user name after loading', async () => {
render(<UserProfileuserId={123} />);
awaitwaitFor(() => {
expect(screen.getByText('John Doe')).toBeInTheDocument();
});
});
4. Use Coverage to Find Gaps, Not as Goal
Coverage is a tool, not a target.
Anti-pattern: Writing useless tests to hit 100%
Better: Writing meaningful tests, accepting 85-90%
5. Automate Coverage Checks
CI/CD Integration:
# .github/workflows/test.yml-name:Runtestswithcoveragerun:npmtest----coverage-name:Checkcoveragethresholdrun:|
COVERAGE=$(jq '.total.lines.pct' coverage/coverage-summary.json)
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
echo "Coverage $COVERAGE% below 80%"
exit 1
fi
Pre-commit Hook:
#!/bin/bash# Run tests on changed files
CHANGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.ts$')
if [ -n "$CHANGED_FILES" ]; then
npm test -- --findRelatedTests $CHANGED_FILES --coverage
fi
Examples
Example 1: New Feature Coverage Check
Request:
I just added user profile editing. Check test coverage for this feature.
Analysis Process:
Find related files (UserProfile.tsx, useUserProfile.ts, updateUser API)
Run coverage for those files
Identify untested paths
Generate test recommendations
Report:
User Profile Feature Coverage: 58%
Files:
- UserProfile.tsx: 72% (needs: error handling tests)
- useUserProfile.ts: 45% (needs: loading state, error state)
- updateUser.ts: 67% (needs: validation error cases)
Critical Gaps:
- No test for update failure
- No test for network error
- No test for validation errors
Recommended Tests: 8
Estimated Coverage After: 89%
Example 2: Pre-Deployment Coverage Gate
Request:
Check if we meet 80% coverage threshold for deployment
We're refactoring the auth module. What's our test coverage there?
Analysis:
Auth Module Coverage: 34%
Risk Assessment: HIGH
- 66% of code is untested
- No tests for password reset
- No tests for session expiry
- Limited tests for error cases
Recommendation: STOP
Before refactoring:
1. Increase coverage to 80%+ (add 23 tests)
2. Add integration tests for auth flow
3. Document expected behavior
Refactoring without tests = high regression risk
Stack-Specific Patterns
React/TypeScript (Jest + RTL)
Coverage Command:
npm test -- --coverage --collectCoverageFrom='src/**/*.{ts,tsx}'
Common Gaps:
Error boundaries not triggered
Loading states not tested
useEffect cleanup not tested
Event handlers not tested
Go
Coverage Command:
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
Common Gaps:
Error return paths
Defer cleanup functions
Context cancellation
Goroutine error handling
Rust
Coverage Command:
cargo tarpaulin --out Html --output-dir coverage
Common Gaps:
Error enum variants
Match arm branches
Panic paths
Unsafe blocks (should be 100%)
Conclusion
Test coverage analysis identifies gaps, prioritizes testing efforts, and ensures code quality. Use this skill regularly to maintain high coverage, catch regressions early, and ship with confidence.
Key Takeaways:
Measure coverage regularly (every commit)
Focus on critical code paths first
Branch coverage > line coverage
Coverage is a tool, not a goal
Automate coverage checks in CI/CD
For security analysis, see the audit skill. For performance optimization, see the optimize skill.