Skip to main content
skill CX Codex

test-driven-development · mikeyobrien — Claude Code skill: the RED-GREEN-REFACTOR

This skill walks the agent through RED → GREEN → REFACTOR and makes it write tests before code. Useful when a spec or task needs to become checkable tests.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add mikeyobrien/ralph-orchestrator --skill test-driven-development -a claude-code
Open on GitHub

What test-driven-development does

The skill takes three kinds of input. Point it at a .spec.md file with Given/When/Then criteria and it parses the spec, then generates one test stub per criterion with a todo!() body. Point it at a .code-task.md file or a plain description and the agent first finds the existing test patterns in the repo, then writes failing tests for the requirements.

From there it is one loop: RED means tests fail for the right reason, GREEN means the minimum implementation with nothing extra, REFACTOR means cleanup with a test run after every change. Before writing anything, the skill suggests reading 2-3 nearby test files and mirroring their module layout, fixture helpers and assertion style.

Property tests get their own section on proptest: use it only for pure functions with deterministic output and a non-trivial input space. Pulling proptest in as a new dependency without a strong reason is discouraged. Completion events carry coverage evidence, for example ralph emit "build.done" "tests: pass, lint: pass, typecheck: pass, audit: pass, coverage: pass (82%)". If coverage cannot be run, say why and attach targeted test evidence instead.

What it helps with

  • turn a Given/When/Then spec into individual tests
  • get failing tests in place before any implementation
  • mirror the test patterns of the crate you are editing
  • decide whether a property test is warranted or an example test will do
  • attach coverage evidence to a completion event

Example prompts for the agent

  • parse the .spec.md and generate a test stub for each criterion
  • write failing tests for this task first, then the minimal implementation
  • check whether proptest fits here and justify it

How to install test-driven-development

1Skills CLI (Vercel)

npx skills add mikeyobrien/ralph-orchestrator --skill test-driven-development -a claude-code

2Manually: put the files in place

~/.claude/skills/test-driven-development/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/test-driven-development/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about test-driven-development

How do I install test-driven-development in Claude?

Run npx skills add mikeyobrien/ralph-orchestrator --skill test-driven-development -a claude-code. The skill lands at ~/.claude/skills/test-driven-development/SKILL.md.

What does test-driven-development do?

It drives the agent through RED → GREEN → REFACTOR: failing tests first, then a minimal implementation, then cleanup. It works from a spec, a task file or a plain description.

When does the skill recommend proptest?

Only when the function is pure, the output is deterministic and the input space or edge cases are non-trivial. It advises against adding the dependency without a strong reason.

Source text

SKILL.md · MIT
---
name: test-driven-development
description: Unified TDD skill with three input modes — from spec, from task, or from description. Enforces test-first development using repository patterns, with proptest guidance and backpressure integration.
type: anthropic-skill
version: "1.0"
metadata:
  internal: true
---

# Test-Driven Development

## Overview

One skill for all TDD workflows. Enforces test-first development using existing repository patterns. Three input modes handle different entry points — specs, task files, or ad-hoc descriptions — but the core cycle is always RED → GREEN → REFACTOR.

## Input Modes

Detect the input type and follow the corresponding mode:

### Mode A: From Spec (`.spec.md`)

Use when the input references a `.spec.md` file with Given/When/Then acceptance criteria.

1. **Locate and parse** the spec file — extract all Given/When/Then triples
2. **Generate one test stub per criterion** with `todo!()` bodies:
   ```rust
   /// Spec: <spec-file> — Criterion #<N>
   /// Given <given text>
   /// When <when text>
   /// Then <then text>
   #[test]
   fn <spec_name>_criterion_<N>_<slug>() {
       todo!("Implement: <then text>");
   }
   ```
3. **Verify stubs compile** but fail: `cargo test --no-run -p <crate>`
4. Proceed to the [TDD Cycle](#tdd-cycle) to make stubs pass

**Programmatic support:** `ralph_core::preflight::{extract_acceptance_criteria, extract_criteria_from_file, extract_all_criteria}` can parse criteria from spec files.

### Mode B: From Task (`.code-task.md`)

Use when the input references a `.code-task.md` file or a specific implementation task.

1. **Read the task** and identify acceptance criteria or requirements
2. **Discover patterns** (see [Pattern Discovery](#pattern-discovery))
3. **Design test scenarios** covering normal operation, edge cases, and error conditions
4. **Write failing tests** for all requirements before any implementation
5. Proceed to the [TDD Cycle](#tdd-cycle)

### Mode C: From Description

Use for ad-hoc tasks without a spec or task file.

1. **Clarify requirements** from the description
2. **Discover patterns** (see [Pattern Discovery](#pattern-discovery))
3. **Write failing tests** targeting the described behavior
4. Proceed to the [TDD Cycle](#tdd-cycle)

## Pattern Discovery

Before writing tests, discover existing conventions:

```bash
rg --files -g "crates/*/tests/*.rs"
rg -n "#\[cfg\(test\)\]" crates/
```

Read 2-3 relevant test files near the target code. Mirror:
- Test module layout, naming, and assertion style
- Fixture helpers and test utilities
- Use of `tempfile`, scenarios, or harnesses

## TDD Cycle

### 1) RED — Failing Tests

- Write tests for the exact behavior required
- Run tests to confirm failure **for the right reason**
- If tests pass without implementation, the test is wrong

### 2) GREEN — Minimal Implementation

- Write the minimum code to make tests pass
- No extra features or refactoring during this step

### 3) REFACTOR — Clean Up

- Improve implementation and tests while keeping tests green
- Align with surrounding codebase conventions
- Re-run tests after every change

## Proptest Guidance

Use `proptest` only when ALL of:
- Function is pure (no I/O, no time, no globals)
- Deterministic output for given input
- Non-trivial input space or edge cases

```rust
proptest! {
    #[test]
    fn round_trip(input in "[a-z0-9]{0,32}") {
        let encoded = encode(input.as_str());
        let decoded = decode(&encoded).expect("should decode");
        prop_assert_eq!(decoded, input);
    }
}
```

Don't introduce proptest as a new dependency without strong justification.

## Backpressure Integration

Include coverage evidence in completion events:

```bash
ralph emit "build.done" "tests: pass, lint: pass, typecheck: pass, audit: pass, coverage: pass (82%)"
```

Run `cargo tarpaulin --out Html --output-dir coverage --skip-clean` when feasible. If coverage cannot be run, state why and include targeted test evidence instead.

## Test Location Rules

- Spec maps to a single module → inline `#[cfg(test)]` tests
- Spec spans multiple modules → integration test in `crates/<crate>/tests/`
- CLI behavior → `crates/ralph-cli/tests/`
- Follow existing patterns in the target crate

## Anti-Patterns

- Writing implementation before tests
- Generating tests that pass without implementation
- Copying tests from other crates without adapting to local patterns
- Adding proptest when a simple example test suffices
- Emitting completion events without coverage evidence

© mikeyobrien · MIT · mikeyobrien/ralph-orchestrator

Similar skills

All skills for Testing and QA →

test-driven-development by other authors comes first.

test-driven-development Jesse Vincent This skill guides an agent through test-first development: verify a test fails, write the smallest passing change, then refactor. It covers features, bug fixes, and behavior changes. CX Codex 259,292installs test-driven-development addyosmani This skill guides work through red-green-refactor: write a failing test, add the smallest passing code, then refactor. Use it for logic, bugs, and behavior changes. CX Codex +1 62,000installs test-driven-development Hermes Agent (adapted from obra/superpowers) Skill that embeds TDD into your workflow: write the test first, watch it fail, then code. Forces you to see failing tests before implementation, reducing bugs and enabling safe refactoring. CX Codex +1 478installs test-driven-development sickn33 Guides coding agents through a strict test-driven development workflow: red, green, and refactor. Useful when fixing bugs or implementing new features with regression checks. CX Codex +1 1,400installs rust-testing affaan-m A skill for writing Rust tests: unit, integration, async, property-based, mocks and coverage. Useful when the project runs on TDD. CX Codex +1 5,600installs spec-driven-workflow Alireza Rezvani Makes the agent write a specification before any code: requirements, acceptance criteria, scope limits. Useful when a feature needs thinking through first. 600installs constraint-driven-development addyosmani Turns a project's quality bar into CONSTRAINTS.md with real numbers, then watches the diff for weakened checks and deleted tests. CX Codex +1 33,400installs test-skill NeoLabHQ Tests agent skills before deployment using a TDD cycle with pressure scenarios. Reveals when an assistant bypasses rules and invents excuses. CX Codex +1 1,200installs rtk-tdd rtk-ai This skill enforces a Red-Green-Refactor workflow for Rust and activates on implementation, testing, refactoring, and bug-fixing tasks. CX Codex +1 2,100installs tdd-rust rtk-ai Skill for RTK filter development using TDD. Write a test with real data, implement minimum code, verify token savings, lock the output format with insta snapshots. CX Codex +1 1,400installs

From the same set4

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor