# Tdd

> TDD (Test-Driven Development)

- Skill: `jh941213/tdd-2` (Agent Skill)
- Install (CLI): `npx skillmds@latest add jh941213/tdd-2`
- Raw SKILL.md: https://api.skillmd.com/api/skills/jh941213/tdd-2/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: jh941213 (https://skillmd.com/u/jh941213)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/jh941213/tdd-2

---


# TDD (Test-Driven Development)

Applies TDD methodology: write tests first, then implement code.

## TDD Cycle

```
RED -> GREEN -> REFACTOR -> REPEAT

RED:      Write a failing test
GREEN:    Write minimal code to pass the test
REFACTOR: Improve code (keeping tests passing)
REPEAT:   Next feature/scenario
```

## Procedure

1. **Define Interface** (SCAFFOLD)
   - Define types/interfaces first
   - Write function signatures

2. **Write Tests** (RED)
   - Happy path
   - Edge cases (empty values, null, max values)
   - Error cases

3. **Run Tests - Confirm Failure**
   ```bash
   npm test -- path/to/file.test.ts
   ```

4. **Minimal Implementation** (GREEN)
   - Only enough code to pass the tests

5. **Refactor** (REFACTOR)
   - Improve code while keeping tests passing

6. **Check Coverage**
   ```bash
   npm test -- --coverage
   ```
   - Target: 80% or higher

## Precautions

- Write tests first (before implementation!)
- Write only one test at a time
- Always verify the test fails first
- Write only minimal code

