home / skills / shotaiuchi / dotclaude / refactor-test

refactor-test skill

/dotclaude/skills/refactor-test

This skill analyzes test coverage and identifies gaps to guide pre-refactoring tests and verification checkpoints, reducing risk during code changes.

npx playbooks add skill shotaiuchi/dotclaude --skill refactor-test

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.0 KB
---
name: refactor-test
description: >-
  Test coverage verification for refactoring. Apply when verifying existing
  test coverage, identifying gaps, recommending pre-refactoring tests,
  and defining verification checkpoints.
user-invocable: false
---

# Test Guardian Analysis

Verify existing test coverage and ensure tests will catch regressions during refactoring.

## Analysis Checklist

### Existing Coverage Analysis
- Map test coverage for all files in the refactoring scope
- Identify which behaviors are covered by unit vs integration tests
- Check for tests that depend on implementation details (brittle tests)
- Verify edge cases and error paths are covered

### Gap Identification
- Find critical code paths with no test coverage
- Identify untested boundary conditions and error handling
- Detect missing integration tests between affected modules
- Check for untested concurrent or async behavior

### Pre-Refactoring Tests
- Recommend characterization tests to capture current behavior
- Define golden master tests for complex output verification
- Suggest contract tests for public API boundaries
- Plan snapshot tests for UI components affected by changes

### Verification Checkpoints
- Define test gates between each migration step
- Specify performance benchmarks to verify no regression
- Plan smoke tests for critical user journeys
- Establish monitoring checks for post-deployment verification

### Test Refactoring Readiness
- Identify brittle tests that will break from structural changes
- Recommend test rewrites to depend on behavior not implementation
- Check test isolation to prevent cascade failures
- Verify test data setup is independent of internal structure

## Output Format

Report findings with impact ratings:

| Impact | Description |
|--------|-------------|
| Breaking | Missing tests for critical path, refactoring unsafe to start |
| High | Significant coverage gap that must be filled before proceeding |
| Medium | Coverage gap that should be addressed during refactoring |
| Low | Minor gap, acceptable risk with manual verification |

Overview

This skill verifies test coverage and readiness before refactoring to reduce regression risk. It maps current tests, identifies coverage gaps, and produces prioritized recommendations and verification checkpoints. The goal is to make refactoring safe, measurable, and incremental.

How this skill works

The skill inspects test suites and source files in the refactoring scope, classifies tests as unit, integration, or brittle implementation-dependent tests, and highlights untested code paths. It outputs a gap analysis with impact ratings, recommends characterization and golden-master tests, and defines stepwise verification gates and post-deployment checks.

When to use it

  • Before starting any non-trivial refactor of existing code
  • When migrating modules, APIs, or shared libraries
  • Prior to changing business logic, error handling, or async/concurrent code
  • To validate readiness for large-scale cleanup or performance optimizations
  • When preparing a safe rollout with incremental verification checkpoints

Best practices

  • Map coverage per file and per behavior, not just overall percentage
  • Prioritize tests for critical paths and public APIs first
  • Add characterization or golden-master tests for complex or poorly understood behavior
  • Convert brittle tests to behavior-driven assertions that avoid implementation details
  • Define test gates and smoke tests for each migration step and include performance checks

Example use cases

  • Verify tests cover authentication, authorization, and payment flows before refactoring core services
  • Identify missing integration tests between frontend rendering and backend APIs before UI refactor
  • Create golden-master tests to lock complex serialization formats before changing serializers
  • Plan test gates and smoke tests when splitting a monolith into services
  • Add contract tests for public APIs before modifying endpoints or payload shapes

FAQ

What output will I get?

A prioritized report that maps coverage, lists gaps with Impact ratings (Breaking/High/Medium/Low), recommends pre-refactoring tests, and defines verification checkpoints.

How do you rate impact?

Impact is based on whether missing tests affect critical user paths or public contracts: Breaking (unsafe), High (must fix), Medium (address during refactor), Low (acceptable risk).