No. 100 Pin the behavior

Test-Driven Development (TDD) Workflow

Use when the behavior should be pinned by a test, not only by a reading of the diff

  • Claude Code
  • Codex
  • Cursor
  • Pin the behavior

Prompt

# Test-Driven Development (TDD) Workflow

I'll help you implement changes using Test-Driven Development. This is an Anthropic-favorite workflow that ensures high-quality, well-tested code.

## TDD Process Overview

I'll follow these steps strictly:
1. **Write failing tests first** - Based on your requirements
2. **Verify tests fail** - Confirm we're testing the right thing
3. **Implement minimal code** - Just enough to make tests pass
4. **Refactor if needed** - Improve code while keeping tests green

## Your Requirements

Please provide:
1. **What feature/change do you want?**
   - Describe the expected behavior
   - Include any edge cases to handle

2. **Test examples (optional but helpful):**
   - Input/output pairs
   - Error scenarios
   - Performance requirements

3. **Test framework preferences:**
   - Which testing framework does your project use?
   - Any specific test patterns to follow?

## Important Notes

- I will **NOT** write any implementation code until tests are written and failing
- I will **NOT** modify tests once we start implementation (unless there's a bug in the test itself)
- I will use your project's test commands to run tests efficiently
- I'll identify the appropriate test command from your project setup

## Process I'll Follow

### Phase 1: Test Creation
```bash
# 1. Analyze existing test structure
chs find-file "*.test.*"
chs find-file "*.spec.*"

# 2. Write comprehensive tests
# 3. Run tests and confirm they fail
```

### Phase 2: Implementation
```bash
# 1. Write minimal implementation
# 2. Run tests repeatedly until all pass
# 3. Avoid overfitting to specific test cases
```

### Phase 3: Verification
```bash
# 1. Run full test suite
# 2. Check test coverage if available
# 3. Commit when all tests pass
```

Let's begin! What would you like to implement using TDD?

When to use

“Test-Driven Development (TDD) Workflow” fits when the behavior should be pinned by a test, not only by a reading of the diff, because it says “Test-Driven Development (TDD) Workflow”, and its first written step is “Write failing tests first - Based on your requirements”.

For “Test-Driven Development (TDD) Workflow”, the extra line you type is the requirement those steps ask for, for example “make src/cart.js return 0 on an empty cart and skip a line with no price”, and the file then starts at “Write failing tests first - Based on your requirements”.

When not to use

Leave “Test-Driven Development (TDD) Workflow” unused when the failing test is already written and you only want it explained. The command's next step is to write tests, not to explain a test you already have.

How to run it

Claude Code

Claude Code stores “Test-Driven Development (TDD) Workflow” as a Claude command and runs it with that command, putting the requirement in the argument, and CLAUDE.md should not also carry “Test-Driven Development (TDD) Workflow”.

Codex

Codex takes “Test-Driven Development (TDD) Workflow” as a paste above the task. Leave AGENTS.md unchanged so the next thread does not inherit “Test-Driven Development (TDD) Workflow”.

Cursor

Cursor should see “Test-Driven Development (TDD) Workflow” only as a chat paste of “Test-Driven Development (TDD) Workflow” for this turn. A file at .cursor/rules would keep applying after the turn ends.

Comparison

Without “Test-Driven Development (TDD) Workflow”, the 2026-12-02 deepseek-v4.1-flash run printed only a corrected total function: an empty cart returns 0 and a missing price falls back to 0. With “Test-Driven Development (TDD) Workflow” prepended, that same run wrote a node:test file first, covering the empty cart, the last line, and a missing price, and only then printed the function. The module under test was src/cart.js.

Related

来源:Darin Cassler · https://github.com/cassler/awesome-claude-code-setup/blob/main/commands/tdd.md · MIT · Copyright (c) 2025 Darin Cassler · 2026-12-01