tdd-red-green-refactor
Kent Beck's TDD workflow. Use when writing new code or modifying existing behavior. Enforces the Red-Green-Refactor cycle with small, verifiable steps.
Best use case
tdd-red-green-refactor is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Kent Beck's TDD workflow. Use when writing new code or modifying existing behavior. Enforces the Red-Green-Refactor cycle with small, verifiable steps.
Teams using tdd-red-green-refactor should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/tdd-red-green-refactor/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How tdd-red-green-refactor Compares
| Feature / Agent | tdd-red-green-refactor | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Kent Beck's TDD workflow. Use when writing new code or modifying existing behavior. Enforces the Red-Green-Refactor cycle with small, verifiable steps.
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
Best AI Skills for Claude
Explore the best AI skills for Claude and Claude Code across coding, research, workflow automation, documentation, and agent operations.
Cursor vs Codex for AI Workflows
Compare Cursor and Codex for AI coding workflows, repository assistance, debugging, refactoring, and reusable developer skills.
SKILL.md Source
# TDD: Red-Green-Refactor ## Rule Anchor - `AGENTS.md` > "Build Requirements" - `AGENTS.md` > "Test-Driven Development" ## Core Principles (Kent Beck) 1. **Never write production code without a failing test.** 2. **Write only enough test to fail** (compilation failure counts as failure). 3. **Write only enough production code to pass the failing test.** 4. **Refactor only when all tests are green.** ## The Cycle ``` RED → GREEN → REFACTOR → RED → ... ``` ### RED: Write a Failing Test - Write one small test that describes the next behavior increment. - Run the test. It must fail. - If it passes, the test is not adding value — rethink what behavior is missing. ### GREEN: Make It Pass - Write the simplest code that makes the failing test pass. - Do not generalize, optimize, or clean up yet. - "Fake it till you make it" is valid — hardcoded returns are acceptable at this step. - Run all tests. They must all pass. ### REFACTOR: Clean Up - Remove duplication between test and production code. - Improve naming, extract methods, simplify logic. - Do not add new behavior during refactoring. - Run all tests after every refactoring move. They must stay green. ## Execution Steps 1. **Identify the next behavior increment.** - What is the smallest observable behavior change? - Express it as a single test case. 2. **Write the test (RED).** ```bash pnpm --filter @robota-sdk/<pkg> test # must FAIL ``` 3. **Write minimal production code (GREEN).** ```bash pnpm --filter @robota-sdk/<pkg> test # must PASS ``` 4. **Refactor (GREEN stays GREEN).** ```bash pnpm --filter @robota-sdk/<pkg> test # must still PASS ``` 5. **Repeat from step 1** until the feature is complete. 6. **Build verification** after the feature is done. ```bash pnpm --filter @robota-sdk/<pkg> build pnpm --filter @robota-sdk/<pkg> test ``` ## Step Size - If a step feels too big, break it into smaller steps. - If a step feels trivial, you can take a slightly larger step — but return to small steps when things get uncertain. - Kent Beck: "Make the change easy, then make the easy change." ## Test List Before starting, write a test list — a simple checklist of behaviors to cover: ``` - [ ] empty input returns empty result - [ ] single item returns that item - [ ] multiple items returns sorted - [ ] duplicate items are preserved - [ ] null input throws ValidationError ``` Work through the list one test at a time. Add new items as you discover them. Cross off completed items. ## Triangulation When unsure how to generalize: 1. Write a second test with a different example for the same behavior. 2. Now generalize the production code to handle both cases. 3. This avoids premature abstraction. ## Stop Conditions - Do NOT write multiple tests at once before making any pass. - Do NOT refactor while tests are red. - Do NOT add behavior during refactoring. - Do NOT skip the failing-test step — "I know this works" is not a substitute. - Do NOT write production code that is not demanded by a failing test. ## When to Apply - New feature implementation. - Bug fixes: write a test that reproduces the bug first, then fix. - Refactoring existing untested code: add characterization tests first, then refactor. ## When NOT to Apply Strictly - Exploratory prototyping (spike) — but discard spike code and rewrite with TDD. - Trivial configuration changes or documentation-only changes. - Generated code or boilerplate that has no behavioral logic. ## Anti-Patterns - **Test-after**: writing all production code first, then adding tests. Tests become verification, not design drivers. - **Big steps**: writing a large test that requires many production code changes at once. - **Gold plating**: adding production code "just in case" that no test demands. - **Refactoring in RED**: changing code structure while tests are failing. - **Skipping RED**: assuming the test would fail without actually running it. ## Related Skills - `vitest-testing-strategy` — testing patterns and structure - `repo-change-loop` — build/test/verify workflow - `type-boundary-and-ssot` — type system, quality gates, and SSOT ownership
Related Skills
pre-refactor-test-harness
Before modularizing or refactoring a package, analyze the code for extraction points, write characterization tests for current behavior, then modularize under test protection. Use when a package has monolithic files that need to be broken into testable modules.
web-design-guidelines
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".
vitest-testing-strategy
Defines a practical testing strategy for TypeScript and JavaScript using Vitest across unit, integration, and type-level tests. Use when adding features, refactoring, or preventing regressions with fast feedback loops.
version-management
All packages must have the same version. Use changesets for coordinated version bumps. Never version packages independently.
vercel-react-native-skills
React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.
vercel-react-best-practices
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
vercel-composition-patterns
React composition patterns that scale. Use when refactoring components with boolean prop proliferation, building flexible component libraries, or designing reusable APIs. Triggers on tasks involving compound components, render props, context providers, or component architecture. Includes React 19 API changes.
user-request-gate
Use immediately when the user requests any implementation, code change, feature addition, fix, or modification. Gates code writing behind a backlog draft document. Read-only exploration is always permitted.
type-boundary-and-ssot
Applies Robota's preferred workflow for trust-boundary validation, strict typing, quality gates, and owner-based SSOT reuse. Use when adding or reviewing type contracts, boundary parsing, shared contract ownership, or running quality checks.
task-tracking
Track work using task files in .agents/tasks/. Use when starting, progressing, or completing a task to maintain a persistent record of work.
tailwind-truncation
Provide Tailwind truncation patterns for single-line and multi-line text. Use when discussing text ellipsis, truncation, or line-clamp usage.
state-machine-design
Designs finite state machines as pure, declarative transition tables with guards and actions. Use when modeling lifecycle states, status flows, or any system with discrete states and controlled transitions.