TDD Workflow

SkillAI & models

The tdd-workflow skill is a set of test-driven development principles that guides an AI agent through the RED-GREEN-REFACTOR cycle. It makes the agent write a failing test first, then the minimum code to pass it, then clean up while keeping tests green. It also covers the three laws of TDD, the AAA test pattern, when TDD is worth using, and common anti-patterns to avoid.

Use TDD Workflow in Claude, ChatGPT or Ahel Desktop

Free. Sign in, add TDD Workflow and connect your AI. About a minute.

Also: Claude Code · Cursor · Codex

Then ask your AI: use the TDD Workflow skill

Details

Instructions available. Your AI can read the instructions. Execution depends on the setup they require.

Add the tdd-workflow skill to your agent so it can read the skill file.

TDD WorkflowStart free

What your AI can do with it

  • Write a failing test before any production code (RED)
  • Write the minimum code needed to pass the test (GREEN)
  • Refactor code while keeping all tests green (REFACTOR)
  • Apply the three laws of TDD to each change
  • Structure tests with the Arrange, Act, Assert pattern
  • Avoid anti-patterns such as skipping RED or testing implementation

Getting started

  1. Add the tdd-workflow skill to your agent so it can read the skill file.
  2. Confirm the agent has access to the tools the skill allows: Read, Write, Edit, Glob, Grep, and Bash.
  3. Ask the agent to implement a small feature or bug fix and state that it should follow TDD.
  4. Check that the agent writes a failing test first, then code to pass it, then refactors with tests still green.

What this skill tells your AI

The instructions your AI receives, as published by davila7/claude-code-templates in cli-tool/components/skills/development/tdd-workflow/SKILL.md and read by ahel’s review.

Write tests first, code second.


1. The TDD Cycle

🔴 RED → Write failing test
    ↓
🟢 GREEN → Write minimal code to pass
    ↓
🔵 REFACTOR → Improve code quality
    ↓
   Repeat...

2. The Three Laws of TDD

  1. Write production code only to make a failing test pass
  2. Write only enough test to demonstrate failure
  3. Write only enough code to make the test pass

3. RED Phase Principles

What to Write

FocusExample
Behavior"should add two numbers"
Edge cases"should handle empty input"
Error states"should throw for invalid data"

RED Phase Rules

  • Test must fail first
  • Test name describes expected behavior
  • One assertion per test (ideally)

4. GREEN Phase Principles

Minimum Code

PrincipleMeaning
YAGNIYou Aren't Gonna Need It
Simplest thingWrite the minimum to pass
No optimizationJust make it work

GREEN Phase Rules

  • Don't write unneeded code
  • Don't optimize yet
  • Pass the test, nothing more

5. REFACTOR Phase Principles

What to Improve

AreaAction
DuplicationExtract common code
NamingMake intent clear
StructureImprove organization
ComplexitySimplify logic

REFACTOR Rules

  • All tests must stay green
  • Small incremental changes
  • Commit after each refactor

6. AAA Pattern

Every test follows:

StepPurpose
ArrangeSet up test data
ActExecute code under test
AssertVerify expected outcome

7. When to Use TDD

ScenarioTDD Value
New featureHigh
Bug fixHigh (write test first)
Complex logicHigh
ExploratoryLow (spike, then TDD)
UI layoutLow

8. Test Prioritization

PriorityTest Type
1Happy path
2Error cases
3Edge cases
4Performance

9. Anti-Patterns

❌ Don't✅ Do
Skip the RED phaseWatch test fail first
Write tests afterWrite tests before
Over-engineer initialKeep it simple
Multiple assertsOne behavior per test
Test implementationTest behavior

10. AI-Augmented TDD

Multi-Agent Pattern

AgentRole
Agent AWrite failing tests (RED)
Agent BImplement to pass (GREEN)
Agent COptimize (REFACTOR)

Remember: The test is the specification. If you can't write a test, you don't understand the requirement.

Signals

GitHub stars
32k
Forks
4k
Last commit
Oct 2026

Others that do the same job

Questions

What is the RED-GREEN-REFACTOR cycle?
RED means write a failing test. GREEN means write the minimum code to pass it. REFACTOR means improve the code while all tests stay green. The cycle repeats for each change.
What are the three laws of TDD?
Write production code only to make a failing test pass. Write only enough test to demonstrate failure. Write only enough code to make the test pass.
When is TDD worth using?
TDD has high value for new features, bug fixes, and complex logic. It has low value for exploratory work and UI layout, where a spike followed by TDD works better.
Advanced
Item type
skill
Key
tdd-workflow-davila7
Source
github.com/davila7/claude-code-templates