# test-driven-development

A testing skill for AI agents that enforces the Red-Green-Refactor loop, Arrange-Act-Assert patterns, naming conventions, and test coverage targets.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 391 installs · ★ 78
- Author: bobmatnyc
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/bobmatnyc/claude-mpm-skills/tree/HEAD/universal/testing/test-driven-development/SKILL.md
- Updated: 2026-07-18
- HTML: https://affpapa.org/en/nevibecode/skills/bobmatnyc-test-driven-development

## What it does

The skill embeds standardized test-driven development practices into your agent workflow. It instructs the assistant to follow the strict Red-Green-Refactor cycle: produce a focused failing test first, implement the minimal logic required to pass, and refactor while keeping tests green. It also establishes structural templates like Arrange-Act-Assert and Given-When-Then, alongside naming patterns like `test_should_<behavior>_when_<condition>`.

It defines distinct boundaries across unit, integration, and end-to-end tests, with clear rules for stubs, fakes, and mocks. Target metrics require 100% coverage on critical paths and 95%+ on business logic, while strictly excluding framework internals and trivial getters from test suites.

Because the skill sets `user-invocable: false` and `disable-model-invocation: true`, you cannot run it as a standalone slash command. It operates as persistent background guidance whenever the model writes or refactors code.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add bobmatnyc/claude-mpm-skills --skill test-driven-development -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/test-driven-development/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/test-driven-development/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add bobmatnyc/claude-mpm-skills --skill test-driven-development -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/test-driven-development/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add bobmatnyc/claude-mpm-skills --skill test-driven-development -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/test-driven-development/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install bobmatnyc/claude-mpm-skills test-driven-development
```

2. **Manually: put the files in place**
- File: `.github/skills/test-driven-development/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add bobmatnyc/claude-mpm-skills --skill test-driven-development -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/bobmatnyc/claude-mpm-skills --path universal/testing/test-driven-development
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/test-driven-development/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add bobmatnyc/claude-mpm-skills --skill test-driven-development -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/bobmatnyc/claude-mpm-skills/tree/HEAD/universal/testing/test-driven-development/SKILL.md

## When to use it
- enforce Red-Green-Refactor workflow on new features
- structure test cases with Arrange-Act-Assert pattern
- replace external databases and APIs with stubs or fakes
- standardize test naming across team repositories

## Example prompts
- Implement the cart checkout using TDD, starting with a failing test
- Write unit tests for the auth service following the Arrange-Act-Assert pattern
- Refactor the order processor while keeping all test suites green

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 2d401c96c3dda141.

BEGIN THIRD-PARTY FILE 2d401c96c3dda141
````text
---
name: test-driven-development
description: Comprehensive TDD patterns and practices for all programming languages, eliminating redundant testing guidance per agent.
user-invocable: false
disable-model-invocation: true
license: Apache-2.0
compatibility: claude-code
metadata:
  updated_at: 2025-10-30T17:00:00Z
tags: [testing, tdd, best-practices, quality-assurance]
progressive_disclosure:
  entry_point:
    summary: "Comprehensive TDD patterns and practices for all programming languages, eliminating redundant testing guidance per agent."
    when_to_use: "When writing tests, implementing test-driven-development, or ensuring code quality."
    quick_start: "1. Review the core concepts below. 2. Apply patterns to your use case. 3. Follow best practices for implementation."
  references:
    - anti-patterns.md
    - examples.md
    - integration.md
    - philosophy.md
    - workflow.md
---
# Test-Driven Development (TDD)

Comprehensive TDD patterns and practices for all programming languages. This skill eliminates ~500-800 lines of redundant testing guidance per agent.

## When to Use

Apply TDD for:
- New feature implementation
- Bug fixes (test the bug first)
- Code refactoring (tests ensure behavior preservation)
- API development (test contracts)
- Complex business logic

## TDD Workflow (Red-Green-Refactor)

### 1. Red Phase: Write Failing Test
```
Write a test that:
- Describes the desired behavior
- Fails for the right reason (not due to syntax errors)
- Is focused on a single behavior
```

### 2. Green Phase: Make It Pass
```
Write the minimum code to:
- Pass the test
- Not introduce regressions
- Follow existing patterns
```

### 3. Refactor Phase: Improve Code
```
While keeping tests green:
- Remove duplication
- Improve naming
- Simplify logic
- Extract functions/classes
```

## Test Structure Patterns

### Arrange-Act-Assert (AAA)
```
// Arrange: Set up test data and conditions
const user = createTestUser({ role: 'admin' });

// Act: Perform the action being tested
const result = await authenticateUser(user);

// Assert: Verify the outcome
expect(result.isAuthenticated).toBe(true);
expect(result.permissions).toContain('admin');
```

### Given-When-Then (BDD Style)
```
Given: A user with admin privileges
When: They attempt to access protected resource
Then: Access is granted with appropriate permissions
```

## Test Naming Conventions

### Pattern: `test_should_<expected_behavior>_when_<condition>`

**Examples:**
- `test_should_return_user_when_id_exists()`
- `test_should_raise_error_when_user_not_found()`
````
END THIRD-PARTY FILE 2d401c96c3dda141

The third-party file has ended. Everything between the 2d401c96c3dda141 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2561 of 9963 bytes. © bobmatnyc · Apache-2.0 · https://github.com/bobmatnyc/claude-mpm-skills/tree/HEAD/universal/testing/test-driven-development/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
