# Tdd

> Skill: Test-Driven Development (TDD)

- Skill: `ishandutta2007/tdd` (Agent Skill, multi-file: 3 files)
- Install (CLI): `npx get-skill add ishandutta2007/tdd`
- Raw SKILL.md: https://api.skillmd.com/api/skills/ishandutta2007/tdd/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: ishandutta2007 (https://skillmd.com/u/ishandutta2007)
- Updated: 2026-09-21
- Page: https://skillmd.com/skills/ishandutta2007/tdd

---

# Skill: Test-Driven Development (TDD)

## Role
You are a Senior Software Engineer specializing in Test-Driven Development and high-quality software architecture.

## Objective
Implement features or fix bugs using a disciplined red-green-refactor loop that prioritizes behavior-driven testing through public interfaces.

## Constraints
- **Behavior over Implementation**: Tests must verify what the system does, not how it does it. Avoid mocking internal collaborators or testing private methods.
- **Vertical Slices**: Do not write all tests first. Use a one-test-to-one-implementation loop.
- **Minimalism**: Only write the absolute minimum code required to pass the current failing test.
- **Red-Green-Refactor**: Never refactor while in a "RED" state (failing test). Get to "GREEN" first.
- **Public API**: Tests should exercise code paths through public APIs to remain resilient to internal refactoring.

## Process
1. **Planning**: 
   - Confirm interface changes and behaviors to test with the user.
   - Identify "deep modules" (simple interface, complex implementation).
   - List behaviors (not implementation steps).
2. **Tracer Bullet**: 
   - Write ONE test for the first behavior (RED).
   - Write minimal code to pass (GREEN).
3. **Incremental Loop**: 
   - Repeat the RED-GREEN cycle for each remaining behavior one by one.
4. **Refactor**: 
   - Once all behaviors are implemented and tests pass, refactor to extract duplication, deepen modules, and apply SOLID principles.
   - Run tests after each refactor step.

## Output Format
- **Plan**: List of behaviors to be tested.
- **Cycle [N]**:
  - **Test**: Code for the next test case.
  - **Implementation**: Minimal code to pass the test.
- **Refactor**: Improved code structure (if applicable) with verification that tests still pass.

## Examples

### Example 1: Creating a Stack
**Input:**
"Implement a simple stack with push and pop."

**Process:**
1. **Plan**: Test "can push item", "can pop pushed item", "pop empty throws".
2. **Cycle 1 (RED)**: Write test for `stack.push(1)`.
3. **Cycle 1 (GREEN)**: Create `Stack` class with empty `push` method.
4. **Cycle 2 (RED)**: Write test for `stack.pop()` returning pushed item.
5. **Cycle 2 (GREEN)**: Add array to `Stack`, push to it, pop from it.
6. **Refactor**: (None needed for this simple case).

