Test-Driven Development (TDD) Guide

Guide teams through the Red-Green-Refactor cycle for failing-first tests.

Updated Nov 5, 2025
One-click install
npx skills add https://github.com/mikeyobrien/ghclip --skill test-driven-development-tdd-guide
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Test-Driven Development (TDD) Guide
Source: https://github.com/mikeyobrien/ghclip/tree/main/.claude/skills/test-driven-development
Command: npx skills add https://github.com/mikeyobrien/ghclip --skill test-driven-development-tdd-guide

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This guide outlines the TDD methodology, emphasizing that developers must write failing tests before implementing features to ensure correct behavior and prevent regressions.

Core Features & Use Cases

  • Red-Green-Refactor Cycle: RED: write a failing test; GREEN: implement the simplest code; REFACTOR: improve while keeping tests green.
  • Iron Law: production code requires a failing test first.
  • Verification Checkpoints: ensure tests fail for the right reasons and pass afterward.

Quick Start

Create a minimal failing test for a new feature, write the simplest code to pass, then refactor while keeping tests green.

Frequently Asked Questions about Test-Driven Development (TDD) Guide

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

FAQPage Schema
What is test-driven development and why should I use it?

Test-driven development (TDD) is a methodology where you write failing tests before implementing features, ensuring correct behavior and preventing regressions. It structures work into three phases: RED (write a failing test), GREEN (implement the simplest code to pass), and REFACTOR (improve while keeping tests green).

How do I apply the red-green-refactor cycle in my projects?

Start by writing a minimal failing test for your feature. Next, implement the simplest code necessary to pass that test. Finally, refactor your code to improve quality while ensuring all tests remain green. Repeat this cycle for each feature, bug fix, and refactoring effort.

What's the iron law of TDD and why does it matter?

The iron law of TDD states that production code requires a failing test first. This discipline ensures every feature has test coverage from inception, catches bugs early, and maintains verification checkpoints throughout development at unit, integration, and system levels.

How do I know my tests are failing for the right reasons?

Use verification checkpoints at each stage of the red-green-refactor cycle. Confirm your test fails before writing production code, verify it passes after implementation, and validate that refactoring maintains green tests. This prevents false positives and ensures test quality.

Can I use TDD for bug fixes and refactoring, not just new features?

Yes. TDD applies across feature development, bug fixes, and refactoring scenarios. For bugs, write a failing test that reproduces the issue, fix the code, then refactor. For refactoring, ensure existing tests pass, improve the code, and verify tests remain green.

What's the relationship between TDD and software quality?

TDD enforces discipline by requiring tests before code, catching defects early and preventing regressions. This test-first approach ensures requirements are clear, code is verifiable at each cycle stage, and quality is maintained through continuous verification checkpoints.