tdd-refactor

Refactor code by identifying code smells and applying safe refactoring techniques.

2|Updated Jan 31, 2026
One-click install
npx skills add https://github.com/michaelalber/ai-toolkit --skill tdd-refactor-michaelalber
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tdd-refactor
Source: https://github.com/michaelalber/ai-toolkit/tree/main/skills/tdd-refactor
Command: npx skills add https://github.com/michaelalber/ai-toolkit --skill tdd-refactor-michaelalber

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers improve the internal structure and readability of their code without altering its external behavior, ensuring that tests remain green throughout the process.

Core Features & Use Cases

  • Code Smell Identification: Detects common code smells like duplication, long methods, and feature envy.
  • Guided Refactoring: Provides step-by-step recipes for safe refactoring techniques such as Extract Method, Rename, and Replace Conditional with Polymorphism.
  • Use Case: After implementing a new feature and ensuring all tests pass, you notice a method has become too long and complex. Use this Skill to break it down into smaller, more manageable functions while keeping your test suite green.

Quick Start

Use the tdd-refactor skill to extract the duplicated code block into a new helper function.

Frequently Asked Questions about tdd-refactor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely refactor code without breaking existing tests?

To safely refactor code without breaking tests, follow the Test-Driven Development Green-to-Green rule to ensure behavioral equivalence. This process uses established techniques to improve maintainability while running comprehensive test verification continuously.

What is the best way to identify and fix common code smells?

Identifying and fixing common code smells like duplication, long methods, and feature envy requires structured refactoring techniques. Applying recipes like Extract Method or Replace Conditional with Polymorphism safely enhances code readability.

When do I need to use refactoring techniques in a TDD workflow?

You need refactoring techniques in a TDD workflow during the REFACTOR phase, which occurs after all tests pass. This phase focuses on improving internal code structure and maintainability without altering external behavior.

How do I break down a long complex method into smaller functions?

To break down a long complex method into smaller functions, apply the Extract Method refactoring recipe. This guided technique separates manageable blocks of code while strict test verification ensures the application behavior remains completely unchanged.

Does refactoring guarantee my application behavior stays the same?

Refactoring guarantees application behavior stays the same through strict adherence to the Green-to-Green rule and comprehensive test verification. This ensures behavioral equivalence while you improve internal code quality and readability.