test-driven-development skill
Enforces the RED-GREEN-REFACTOR discipline by requiring agents to write failing tests before implementing minimal code and refactoring.
- GitHub stars
- 44
- Files
- 1
- Last commit
- Apr 12, 2026
- License
- MIT
- Allowed tools
- —
What does the test-driven-development skill do?
test-driven-development enforces the RED-GREEN-REFACTOR discipline by requiring agents to write failing tests before implementing minimal code and refactoring.
Summary generated from the skill's SKILL.md.
About the test-driven-development skill
Developers who want to prevent agents from generating large blocks of untested code can use this skill to enforce a strict development discipline. It requires an agent to follow the red-green-refactor cycle, ensuring that every line of production code is justified by a specific test assertion. By forcing the agent to write a failing test before any implementation, it ensures that test coverage is a structural guarantee rather than an afterthought.
An agent should load this skill when writing new functions, modules, or APIs, or when fixing bugs by first writing a test that exposes the issue. The process relies on running test commands through a shell to confirm failures and passes, eventually producing atomic commits via version control. This method works across platforms like Cursor, VS Code, and Claude Code by using tools like pytest or jest to validate every change through a mandatory refactor phase.
What an agent can do with it
- 1Implementing new software modulesAn agent can build new functions or business logic by first writing a failing test to define the expected behavior.
- 2Fixing existing software bugsWhen a bug is identified, the agent writes a test that reproduces the error before attempting a fix.
- 3Improving code structure safelyDevelopers can use the skill to clean up existing code while ensuring that all tests pass both before and after the changes.
- 4Preventing software regressionsThe skill provides assurance that new changes will not break existing functionality through constant test validation.
Written from the skill's SKILL.md. Every use case is checked against a quote from it.
How to install the test-driven-development skill
Each command copies the skill folder into the client's skills directory. Restart the client or start a new session to load it.Install the test-driven-development skill in Plugin
/plugin marketplace add itallstartedwithaidea/agent-skills /plugin install software-dev-skills@googleadsagent-skills
Install the test-driven-development skill in Claude Code
~/.claude/skills/test-driven-development/SKILL.md
$ npx degit itallstartedwithaidea/agent-skills/skills/software-dev/test-driven-development ~/.claude/skills/test-driven-developmentInstall the test-driven-development skill in Claude Code (project)
.claude/skills/test-driven-development/SKILL.md
$ npx degit itallstartedwithaidea/agent-skills/skills/software-dev/test-driven-development .claude/skills/test-driven-developmentInstall the test-driven-development skill in Codex
~/.agents/skills/test-driven-development/SKILL.md
$ npx degit itallstartedwithaidea/agent-skills/skills/software-dev/test-driven-development ~/.agents/skills/test-driven-developmentInstall the test-driven-development skill in Gemini CLI
~/.gemini/skills/test-driven-development/SKILL.md
$ npx degit itallstartedwithaidea/agent-skills/skills/software-dev/test-driven-development ~/.gemini/skills/test-driven-developmentInstall the test-driven-development skill in Claude.ai
npx degit itallstartedwithaidea/agent-skills/skills/software-dev/test-driven-development test-driven-development && zip -r test-driven-development.zip test-driven-development # claude.ai → Customize → Skills → + → Create skill → Upload a skill → test-driven-development.zip
SKILL.md
View on GitHubTest-Driven Development
Part of Agent Skills™ by googleadsagent.ai™
Description
Test-Driven Development enforces the RED-GREEN-REFACTOR discipline on every code change an agent produces. The agent writes a failing test first, confirms the failure, writes the minimal code to pass, confirms the pass, refactors for clarity, and commits. No production code exists without a corresponding test that demanded its creation.
This skill eliminates the most common agent anti-pattern: generating large blocks of untested code that "look right" but silently break under edge cases. By forcing the agent through the TDD cycle, each line of production code is justified by a specific test assertion. The result is a codebase where test coverage is not an afterthought but a structural guarantee.
The cycle integrates directly with version control. Each RED-GREEN-REFACTOR iteration produces an atomic commit, creating a reviewable history of design decisions. The refactor phase is mandatory—the agent must evaluate naming, duplication, and structural clarity before moving to the next feature increment.
Use When
- Writing any new function, method, or module
- Fixing a bug (write the test that exposes the bug first)
- Refactoring existing code (ensure tests pass before and after)
- The user requests "TDD", "test-first", or "red-green-refactor"
- Building APIs, data transformations, or business logic
- You need confidence that a change does not introduce regressions
How It Works
graph LR
R[RED: Write Failing Test] --> G[GREEN: Minimal Code to Pass]
G --> RF[REFACTOR: Clean Up]
RF --> C[COMMIT: Atomic Commit]
C --> R
style R fill:#e74c3c,color:#fff
style G fill:#2ecc71,color:#fff
style RF fill:#3498db,color:#fff
style C fill:#95a5a6,color:#fff
RED: Write a test that describes the next small behavior increment. Run it. Confirm it fails for the expected reason—not a syntax error or import failure, but a genuine assertion failure. GREEN: Write the simplest production code that makes the test pass. Resist the urge to generalize. REFACTOR: Improve names, extract duplication, simplify control flow. All tests must still pass. COMMIT: Stage and commit with a message referencing the behavior added.
Implementation
# RED: Write the failing test first
def test_calculate_discount_applies_ten_percent_for_orders_over_100():
order = Order(items=[Item(price=150.00)])
result = calculate_discount(order)
assert result == 135.00 # 10% off
# Run: pytest => FAIL (calculate_discount not defined)
# GREEN: Minimal implementation
def calculate_discount(order):
total = sum(item.price for item in order.items)
if total > 100:
return total * 0.9
return total
# Run: pytest => PASS
# REFACTOR: Extract magic numbers
DISCOUNT_THRESHOLD = 100
DISCOUNT_RATE = 0.10
def calculate_discount(order):
total = sum(item.price for item in order.items)
if total > DISCOUNT_THRESHOLD:
return total * (1 - DISCOUNT_RATE)
return total
# Run: pytest => PASS
# git commit -m "feat: apply 10% discount for orders over $100"
Anti-Patterns to Avoid
| Anti-Pattern | Why It Fails |
|---|---|
| Writing tests after code | Tests confirm assumptions, not behavior |
| Testing implementation details | Brittle tests break on valid refactors |
| Skipping the RED step | No proof the test can actually fail |
| Large GREEN steps | Lose traceability of which test drives which code |
| Skipping REFACTOR | Technical debt accumulates silently |
Best Practices
- Each RED-GREEN-REFACTOR cycle should take under 5 minutes
- If GREEN requires more than 10 lines, the test is too ambitious—split it
- Name tests as behavior specifications:
test_<action>_<condition>_<outcome> - Run the full test suite after every REFACTOR, not just the new test
- Commit after each complete cycle to preserve the design narrative
- Use test doubles (mocks, stubs) only at architectural boundaries
Platform Compatibility
| Platform | Support | Notes |
|---|---|---|
| Cursor | Full | Shell tool runs tests inline |
| VS Code | Full | Terminal integration for test runs |
| Windsurf | Full | Cascade executes test commands |
| Claude Code | Full | Direct shell access for pytest/jest |
| Cline | Full | Configurable test runner |
| aider | Partial | Manual test confirmation needed |
Related Skills
- Systematic Debugging - Root cause analysis that starts by writing a failing test reproducing the bug
- Code Review - Quality gate that verifies test coverage alongside production code changes
- Subagent-Driven Development - Isolated subagents that follow TDD cycles independently for each subtask
Keywords
tdd test-driven-development red-green-refactor failing-test-first test-first unit-testing regression-prevention atomic-commits
© 2026 googleadsagent.ai™ | Agent Skills™ | MIT License
Files in this skill
1test-driven-development skill questions
How do I install the test-driven-development skill in Claude Code?
Run npx degit itallstartedwithaidea/agent-skills/skills/software-dev/test-driven-development ~/.claude/skills/test-driven-development. Claude Code loads skills from ~/.claude/skills (all projects) or .claude/skills (one project) and uses a skill when its description matches the task.
Which clients can use the test-driven-development skill?
Any client that reads the Agent Skills format: Claude Code, Codex, Gemini CLI and claude.ai (upload as a ZIP). Scripts in the skill run only where the client allows code execution.
What is the TDD cycle used by this skill?
The cycle consists of RED (writing a failing test), GREEN (writing minimal code to pass), REFACTOR (cleaning up the code), and COMMIT (creating an atomic commit).