test-coverage
The test-coverage skill analyzes your codebase to measure test coverage metrics, identify untested code paths, and find gaps in test quality across multiple technology stacks including JavaScript, Go, Rust, and Python. Use it when measuring overall coverage percentages, discovering critical code that lacks test protection, evaluating branch and function coverage, or preparing for deployments that require minimum coverage thresholds.
git clone --depth 1 https://github.com/MadAppGang/claude-code /tmp/test-coverage && cp -r /tmp/test-coverage/plugins/dev/skills/test-coverage ~/.claude/skills/test-coverageSKILL.md
# Test Coverage Skill
## Overview
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.
**When to Use**:
- Measuring current test coverage
- Identifying untested critical code paths
- Finding gaps before deployment
- Improving test suite quality
- Compliance requirements (80% coverage)
- Refactoring with confidence
- Onboarding new team members
**Technology Coverage**:
- React/TypeScript/JavaScript (Jest, Vitest, React Testing Library)
- Go (go test with coverage)
- Rust (cargo test with tarpaulin)
- Python (pytest with coverage.py)
- Full-stack applications
## Coverage Metrics
### 1. Line Coverage
**Definition**: Percentage of executable lines that are executed by tests.
**Example**:
```typescript
function divide(a: number, b: number): number {
if (b === 0) { // Line 1: COVERED
throw new Error('Div 0'); // Line 2: NOT COVERED
}
return a / b; // Line 3: COVERED
}
// Test only covers normal case
test('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.
**Example**:
```typescript
function getUserStatus(user: User): string {
if (user.isActive) { // Branch 1: true (COVERED)
if (user.isPremium) { // Branch 2: true (NOT COVERED)
return 'premium'; // NOT COVERED
}
return 'active'; // COVERED
}
return 'inactive'; // Branch 1: false (NOT COVERED)
}
// Test only covers active non-premium
test('returns status', () => {
expect(getUserStatus({ isActive: true, isPremium: false })).toBe('active');
});
// Branch Coverage: 33% (1/3 branches)
// Line Coverage: 60% (3/5 lines)
```
**Why Important**: Higher than line coverage, catches edge cases.
### 3. Function Coverage
**Definition**: Percentage of functions that are called at least once in tests.
**Example**:
```typescript
// auth.ts
export function login(user: string, pass: string) { ... } // COVERED
export function logout() { ... } // COVERED
export function resetPassword(email: string) { ... } // NOT COVERED
export function changePassword(old: string, new: string) { ... } // NOT COVERED
// Function Coverage: 50% (2/4 functions)
```
**Red Flag**: Exported functions with 0% coverage.
### 4. Statement Coverage
**Definition**: Percentage of statements executed (similar to line coverage but more granular).
**Difference from Line Coverage**:
```typescript
// Single line, multiple statements
const x = 1, y = 2, z = 3;
// Line coverage: 1 line
// Statement coverage: 3 statements
```
**Use Case**: More precise for minified or compact code.
## Gap Analysis
### Identifying Untested Code
**Priority Levels**:
**CRITICAL** (Must Test):
- Authentication and authorization logic
- Payment processing
- Data validation
- Security checks
- Error handling
- Database transactions
**HIGH** (Should Test):
- Business logic
- API endpoints
- Data transformations
- State management
- Integration points
**MEDIUM** (Nice to Test):
- Utility functions
- Formatters
- Constants
- Simple getters/setters
**LOW** (Optional):
- Type definitions
- Configuration files
- Mock data
### Gap Report Format
```markdown
# Test Coverage Gap Analysis
**Generated**: 2026-01-28 14:32:00
**Coverage**: 68% (Target: 80%)
**Files Analyzed**: 247
**Critical Gaps**: 12 files
## Executive Summary
**Overall Coverage**:
- Line Coverage: 68% (Target: 80%) - 12% below
- Branch Coverage: 54% (Target: 75%) - 21% below
- Function Coverage: 71% (Target: 85%) - 14% below
**Risk Assessment**: MEDIUM-HIGH
- 12 critical files under 50% coverage
- 23 high-priority functions untested
- 47 error handling branches untested
## Critical Gaps (Priority 1)
### [GAP-001] Authentication Module
**File**: src/auth/AuthService.ts
**Line Coverage**: 34% (Target: 95%+)
**Branch Coverage**: 22%
**Risk**: CRITICAL
**Untested Code Paths**:
```typescript
// CRITICAL: No tests for password reset flow
async resetPassword(email: string): Promise<void> {
const user = await this.userRepo.findByEmail(email);
if (!user) {
throw new NotFoundError('User not found'); // UNTESTED
}
const token = generateResetToken(); // UNTESTED
await this.emailService.sendResetEmail( // UNTESTED
user.email,
token
);
}
// CRITICAL: No tests for token expiry
validateResetToken(token: string): boolean {
const decoded = jwt.verify(token, SECRET);
if (Date.now() > decoded.exp) { // UNTESTED
return false;
}
return true;
}
```
**Impact**: Security vulnerability, potential for unauthorized access.
**Recommendation**: Add comprehensive tests for all auth flows.
**Required Tests**:
1. resetPassword with valid email
2. resetPassword with invalid email
3. resetPassword with malformed email
4. validateResetToken with expired token
5. validateResetToken with invalid token
6. validateResetToken with valid token
**Estimated Coverage After**: 88%
---
### [GAP-002] Payment Processing
**File**: src/payments/PaymentService.ts
**Line Coverage**: 41% (Target: 99%+)
**Branch Coverage**: 29%
**Risk**: CRITICAL
**Untested Code Paths**:
```typescript
async processPayment(order: Order): Promise<PaymentResult> {
try {
const charge = await stripe.charges.create({ // TESTED
amount: order.total,
currency: 'usd',
source: order.paymentToken
});
if (charge.status === 'failed') { // UNTESTED
await this.handleFailedPArchitecture Decision Records (ADR) documentation practice. Use when documenting architectural decisions, recording technical trade-offs, creating decision logs, or establishing architectural patterns. Trigger keywords - "ADR", "architecture decision", "decision record", "trade-offs", "architectural decision", "decision log".
Use when deciding whether to launch an agent, selecting which agent to use, or coordinating multiple agents. Covers delegation criteria, external-model patterns, task isolation, and agent selection strategies.
Use when designing REST or GraphQL APIs, defining endpoints, implementing pagination/filtering, handling API versioning, or establishing API documentation with OpenAPI/Swagger.
Use when integrating Apidog + OpenAPI specifications with your React app. Covers MCP server setup, type generation, and query layer integration. Use when setting up API clients, generating types from OpenAPI, or integrating with Apidog MCP.
Analyzes API documentation from OpenAPI specs to provide TypeScript interfaces, request/response formats, and implementation guidance. Use when implementing API integrations, debugging API errors (400, 401, 404), replacing mock APIs, verifying data types, or when user mentions endpoints, API calls, or backend integration.
Use when analyzing architecture and system design. Find design patterns, map layers, identify core abstractions via PageRank. Uses claudemem AST structural analysis for efficient architecture investigation.
On-demand security and code quality audit. Use when checking for vulnerabilities, security issues, code smells, or compliance problems. Trigger keywords - "audit", "security check", "vulnerability scan", "code quality", "compliance", "security audit".
Use when implementing authentication (JWT, sessions, OAuth), authorization (RBAC, ABAC), password hashing, MFA, or security best practices for backend services.