tdd

Guides an AI agent through strict Test-Driven Development (TDD) using the Red-Green-Refactor cycle. It helps implement features from a plan or description, detecting language and test framework.

136 stars
Complexity: easy

About this skill

This AI agent skill meticulously guides the development process through Test-Driven Development (TDD). Upon invocation, it takes either a markdown plan file or an inline feature description as input, decomposing the feature into small, testable increments. The skill then proactively identifies the project's programming language and testing framework, preparing the environment for development. The core of the skill is its strict adherence to the Red-Green-Refactor (RGR) loop for each increment. The agent, empowered by this skill, writes code directly into real project files and prompts the user only when their input or decision is genuinely required, ensuring a streamlined yet collaborative workflow. This systematic approach helps maintain code quality and test coverage throughout the development lifecycle. Developers would use this skill to enforce TDD best practices, ensure robust and test-backed code, and benefit from an AI assistant that understands and applies a disciplined coding methodology. It's particularly useful for projects where high quality and maintainability are paramount, providing a structured way to build out features.

Best use case

The primary use case is for developers and development teams who want to rigorously apply Test-Driven Development principles to their projects. It benefits anyone looking to build new features or refactor existing code with high confidence, ensuring that every piece of functionality is backed by automated tests and developed through a structured, iterative process.

Guides an AI agent through strict Test-Driven Development (TDD) using the Red-Green-Refactor cycle. It helps implement features from a plan or description, detecting language and test framework.

The user will have a new or modified feature implemented via strict Red-Green-Refactor TDD cycles, backed by comprehensive tests, guided by the AI agent.

Practical example

Example input

/tdd add user login with email and password

Example output

Here are the increments I've identified: 1. Create user model, 2. Implement registration endpoint, 3. Add login endpoint. Want to reorder, add, remove, or modify any before we start?
Options: 'Looks good, let's start' / 'I want to modify the list'

When to use this skill

  • When implementing a new feature where test coverage and code quality are critical.
  • To learn or practice the TDD methodology with active guidance from an AI agent.
  • When refactoring existing code and needing to first establish a strong test suite.
  • For projects requiring a disciplined, incremental approach to software development.

When not to use this skill

  • For quick, exploratory coding tasks where the overhead of strict TDD is unnecessary.
  • When working on prototypes or proof-of-concepts where speed trumps immediate test coverage.
  • If the project's language or test framework is highly niche and unsupported by common detection patterns.
  • When a developer prefers a completely unstructured, ad-hoc coding style without incremental guidance.

How tdd Compares

Feature / AgenttddStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityeasyN/A

Frequently Asked Questions

What does this skill do?

Guides an AI agent through strict Test-Driven Development (TDD) using the Red-Green-Refactor cycle. It helps implement features from a plan or description, detecting language and test framework.

How difficult is it to install?

The installation complexity is rated as easy. You can find the installation instructions above.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# TDD Skill — Red-Green-Refactor

You are guiding the developer through strict Test-Driven Development. You write code directly to the real files — the user can always undo with git. Pause only when the user's input is needed, not at every step.

## Phase 1: Setup

1. Determine the input type:
   - **If the input is a file path** (ends in `.md`, `.txt`, or exists on disk): read the plan file.
   - **If the input is an inline description** (e.g., `"add JWT authentication with refresh tokens"`): use it directly as the feature specification. Ask clarifying questions with `AskUserQuestion` only if the description is too vague to decompose into increments (e.g., "build an app"). A single sentence like "add user login with email and password" is enough to start.
2. Detect the language and test framework from the project. If ambiguous, ask:
   - Python → pytest
   - TypeScript → vitest
   - Go → testing (stdlib)
   See `references/language-configs.md` for runner commands and conventions.
3. Break the feature into small, testable increments. See `references/increments.md` for decomposition patterns.
4. Create a task list using `TaskCreate` — one task per increment.
5. Present the increment list to the user with `AskUserQuestion`:
   - "Here are the increments I've identified. Want to reorder, add, remove, or modify any before we start?"
   - Options: "Looks good, let's start" / "I want to modify the list"

## Phase 2: TDD Loop

For each increment, follow Red-Green-Refactor strictly. Mark the current increment as `in_progress` via `TaskUpdate`.

### RED — Write a Failing Test

1. Write the failing test **directly to the real test file** (e.g., `tests/test_feature.py`, following existing project conventions). Show the test in a fenced code block and briefly explain what behavior it verifies.
2. Run the test using the appropriate runner (see language-configs.md). Use `Bash`.
3. Confirm the test **fails**. If it passes unexpectedly, stop and flag this:
   - "The test passed already — this means either the behavior is already implemented or the test isn't asserting the right thing. Let's investigate before moving on."
4. Pause with `AskUserQuestion`:
   - "RED: test fails as expected. Review the test above — ready to move to GREEN?"
   - Options: "Looks good, write the code" / "I want to change the test first"

### GREEN — Write Minimal Code to Pass

5. Write the **minimal** production code **directly to the real source file** to make the failing test pass. Show it in a fenced code block. Write only enough to pass, nothing more.
6. Run **all** tests (not just the new one). Use `Bash`.
7. If all tests **pass**, move directly to REFACTOR — no pause needed.
8. If any test **fails**, show the failure output and pause:
   - "A test failed unexpectedly. Here's the output. Want me to fix it, or do you want to handle it?"
   - Options: "Fix it" / "I'll handle it"

### REFACTOR — Improve the Code

9. Review the current code. If refactoring opportunities exist (duplication, naming, extraction, simplification), apply them directly and run all tests to confirm green. Show what you changed in a fenced code block.
10. If no refactoring is needed, say so and move on — no pause.
11. If refactoring causes a test failure, revert and pause to discuss.

### NEXT

12. Mark the increment as `completed` via `TaskUpdate`.
13. Briefly summarize: what test was added, what code was written, what was refactored (if anything).
14. Move directly to the next increment — go back to RED. No pause between increments.

## Phase 3: Wrap-up

After all increments are complete:

1. Summarize what was built:
   - List each increment and its test
   - Note the final test count and all-passing status
2. Suggest any remaining work (edge cases, integration tests, documentation).

## Rules

- **Write directly to real files.** No temp files, no asking the user to move code. The user has git for undo.
- **Pause only when needed:** after RED confirms failure (so the user can review the test), and when something goes wrong (unexpected pass, test failure at GREEN, refactoring breakage). Do NOT pause at GREEN success or REFACTOR success.
- **Run the full test suite** at Green and Refactor steps, not just the new test.
- **Keep tests behavior-focused.** Test what the code does, not how it does it.
- **Simplest case first.** Start with the degenerate/edge case, build toward the general case.
- **One assertion per test** when possible. Each test should verify one behavior.
- **Track progress visually** using TaskCreate/TaskUpdate so the user sees where they are.
- **Follow existing project conventions.** Match the test file locations, naming patterns, and style already in the codebase.

Related Skills

laravel-expert

31392
from sickn33/antigravity-awesome-skills

Senior Laravel Engineer role for production-grade, maintainable, and idiomatic Laravel solutions. Focuses on clean architecture, security, performance, and modern standards (Laravel 10/11+).

Coding & DevelopmentClaude

debug-nw

7754
from nativewind/nativewind

Debug a Nativewind v5 setup issue. Walks through common configuration problems with metro, babel, postcss, and dependencies.

Coding & Development

Go Production Engineering

3891
from openclaw/skills

You are a Go production engineering expert. Follow this system for every Go project — from architecture decisions through production deployment. Apply phases sequentially for new projects; use individual phases as needed for existing codebases.

Coding & Development

Database Engineering Mastery

3891
from openclaw/skills

> Complete database design, optimization, migration, and operations system. From schema design to production monitoring — covers PostgreSQL, MySQL, SQLite, and general SQL patterns.

Coding & Development

afrexai-code-reviewer

3891
from openclaw/skills

Enterprise-grade code review agent. Reviews PRs, diffs, or code files for security vulnerabilities, performance issues, error handling gaps, architecture smells, and test coverage. Works with any language, any repo, no dependencies required.

Coding & Development

API Documentation Generator

3891
from openclaw/skills

Generate production-ready API documentation from endpoint descriptions. Outputs OpenAPI 3.0, markdown reference docs, and SDK quickstart guides.

Coding & Development

bili-rs

3891
from openclaw/skills

Development skill for bili-rs, a Rust CLI tool for Bilibili (B站). Use when implementing features, fixing bugs, or extending the bilibili-cli-rust codebase. Provides architecture conventions, API endpoints, coding patterns, and project-specific constraints. Triggers on tasks involving adding CLI commands, calling Bilibili APIs, handling authentication, implementing output formatting, or working with the layered cli/commands/client/payloads architecture.

Coding & Development

Puppeteer

3891
from openclaw/skills

Automate Chrome and Chromium with Puppeteer for scraping, testing, screenshots, and browser workflows.

Coding & Development

pharaoh

3891
from openclaw/skills

Codebase knowledge graph with 23 development workflow skills. Query architecture, dependencies, blast radius, dead code, and test coverage via MCP. Requires GitHub App installation (read-only repo access) and OAuth authentication. Connects to external MCP server at mcp.pharaoh.so.

Coding & Development

git-commit-helper

3891
from openclaw/skills

Generate standardized git commit messages following Conventional Commits format. Use this skill when the user asks to commit code, write a commit message, or create a git commit. Enforces team conventions for type prefixes, scope naming, message length, and breaking change documentation.

Coding & Development

ask-claude

3891
from openclaw/skills

Delegate a task to Claude Code CLI and immediately report the result back in chat. Supports persistent sessions with full context memory. Safe execution: no data exfiltration, no external calls, file operations confined to workspace. Use when the user asks to run Claude, delegate a coding task, continue a previous Claude session, or any task benefiting from Claude Code's tools (file editing, code analysis, bash, etc.).

Coding & Development

bnbchain-mcp

3891
from openclaw/skills

Interact with the BNB Chain Model Context Protocol (MCP) server. Blocks, contracts, tokens, NFTs, wallet, Greenfield, and ERC-8004 agent tools. Use npx @bnb-chain/mcp@latest or read the official skill page.

Coding & Development