S

Smart Test Coverage

Boost productivity using this analyze, improve, test, coverage. Includes structured workflows, validation checks, and reusable patterns for testing.

CommandClipticstestingv1.0.0MIT
0 views0 copies

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

ConceptDescription
Line coveragePercentage of executable lines hit during tests
Branch coverageWhether both true/false paths of conditionals are tested
Function coverageWhether each function has been called at least once
Priority scoreCombines complexity, change frequency, and criticality
Source Files ---> Coverage Tool ---> Raw Report
                                        |
                              +---------+---------+
                              |         |         |
                           Lines    Branches  Functions
                              \         |         /
                               +--- Priority ---+
                                       |
                              Ranked Recommendations

Configuration

OptionDefaultDescription
threshold80Target coverage percentage
formatsummaryOutput format (summary, detailed, json)
includesrc/Directories to include in analysis
excludenode_modules,distPaths to exclude
sort-byprioritySort uncovered items (priority, name, coverage)

Best Practices

  1. Set realistic thresholds -- 80% is a solid target; pushing to 100% often leads to brittle tests of trivial code.
  2. Focus on branch coverage -- line coverage can be misleading when conditionals are only half-tested.
  3. Prioritize by risk -- cover payment, auth, and data-mutation code before formatting utilities.
  4. Track trends over time -- a coverage number matters less than whether it is going up or down.
  5. Exclude generated code -- auto-generated files inflate or deflate coverage numbers unfairly.

Common Issues

  1. Coverage tool not found -- Install the appropriate tool: nyc or c8 for Node.js, coverage.py for Python, go test -cover for Go.
  2. Unexpectedly low numbers -- Check that test files are not included in the source count and that mocks are not inflating the denominator.
  3. Slow execution -- Coverage instrumentation adds overhead. Run coverage analysis separately from quick test passes.
Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates