# Test Driven Development

> Use when implementing any feature or bugfix - requires writing a failing test before writing any production code

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

---


# Test-Driven Development

## Overview

Write a failing test first, then implement the minimal code to pass it, then refactor.

**Core principle:** NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST.

**This is mandatory. No exceptions for production code.**

## The Red-Green-Refactor Cycle

### RED: Write Failing Test

1. Write a minimal test demonstrating desired behavior
2. Run test - it MUST fail
3. Verify it fails for the right reason

### GREEN: Implement Minimal Code

1. Write the simplest code to pass the test
2. No extra features, no optimization
3. Run test - it MUST pass

### REFACTOR: Clean Up

1. Improve code while maintaining test pass
2. Remove duplication
3. Improve naming
4. Run tests to ensure nothing breaks

## Why This Matters

- Tests written after code pass immediately - proving nothing
- Manual testing is ad-hoc and non-repeatable
- TDD catches bugs before deployment
- Tests become safety net for future changes

## Critical Requirements

Tests must be:
- **Minimal** - one behavior each
- **Clear** - descriptive naming
- **Real** - avoiding unnecessary mocks

## Verification Checklist

- [ ] Test fails before implementation (RED)
- [ ] Test passes after implementation (GREEN)
- [ ] Refactoring maintains pass
- [ ] Test actually exercises the code

## Red Flags - STOP

- Code written before test
- Tests that pass immediately
- Manual verification instead of tests
- "I'll write tests after"
- Skipping the cycle

**If you wrote code before test:** Delete it. Start over with test first.

## Common Mistakes

| Mistake | Reality |
|---------|---------|
| Test passes immediately | You wrote code before test |
| Manual testing | Ad-hoc, non-repeatable |
| "This is simple" | Simple code breaks too |
| "No time for tests" | Testing saves time by preventing rework |

## Integration

- **Phase 4.1 of debugging** - Create failing test before fixing
- **Plan execution** - Each task includes test-first step
- **Subagent-driven development** - Implementation includes test creation

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/asadullah48) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-13 -->

