# Tdd

> Use when the user wants test-driven development, asks to write tests first, or mentions TDD.

- **Type:** Skill
- **Install:** `agentstack add skill-huzaifa525-claude-code-optimizer-tdd`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [huzaifa525](https://agentstack.voostack.com/s/huzaifa525)
- **Installs:** 0
- **Category:** [Developer Tools](https://agentstack.voostack.com/c/developer-tools)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [huzaifa525](https://github.com/huzaifa525)
- **Source:** https://github.com/huzaifa525/claude-code-optimizer/tree/master/templates/.claude/skills/tdd
- **Website:** https://www.npmjs.com/package/claude-code-optimizer

## Install

```sh
agentstack add skill-huzaifa525-claude-code-optimizer-tdd
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

Implement **$ARGUMENTS** using strict TDD.

## Iron Laws

> **1. No production code exists without a failing test.**
> If you write code before a test, DELETE it. Not "keep as reference." Not "adapt it." DELETE it.
>
> **2. Write the MINIMUM code to pass the test.**
> If the test passes, STOP writing code. More code = more bugs = more maintenance.
>
> **3. Delete means delete.**
> If you wrote code before the test: don't keep it as reference, don't paste it somewhere, don't look at it. Delete it and write the test first. Your memory of the solution will make reimplementation fast.

## Cycle

### 1. RED — Write a Failing Test

- Find existing test files to match the naming pattern
- Write ONE test that describes ONE specific behavior
- Run it — confirm it **FAILS**
  ```
  [test command]
  ```
- If it passes without new code, your test is wrong — it's testing something that already exists

### 2. GREEN — Write Minimum Code

- Write the **simplest possible code** that makes the test pass
- No extra features, no "while I'm here" additions, no premature optimization
- Run the test — confirm it **PASSES**
  ```
  [test command]
  ```

### 3. REFACTOR — Clean Up

- Improve code quality **without changing behavior**
- Remove duplication, improve naming, simplify logic
- Run **ALL tests** — confirm nothing broke
  ```
  [test command]
  ```

### 4. REPEAT

If the feature needs more behavior:
- Go back to step 1 with the next test case
- Continue until all requirements from $ARGUMENTS are covered
- Each cycle should be small: one test, one behavior

## Anti-Rationalization

| Excuse | Rebuttal |
|--------|----------|
| "I already know the implementation, writing a test first is wasteful" | The test isn't just for verification — it's a specification. Write it. |
| "This is too simple to need TDD" | Simple code is the EASIEST to TDD. No excuse to skip it. |
| "I'll write the tests after" | Tests written after code are weaker — they test what you wrote, not what you should have written. |
| "The test framework isn't set up yet" | Set it up. That's step 0, not a reason to skip testing. |
| "I wrote code first but I can just add a test now" | Delete the code. Write the test. Watch it fail. THEN rewrite the code. This is the discipline. |
| "I need to see the implementation to know what to test" | You need to see the REQUIREMENTS to know what to test. Read the spec, not the code. |
| "Refactoring isn't needed for this small change" | Small changes accumulate. Refactor now while context is fresh. |

## Red Flags (you're doing it wrong if...)

- You wrote more than 10 lines of production code before running a test
- Your test passes on the first run without new code
- You're "refactoring" by adding new features
- You have untested edge cases and you're moving to the next feature
- You wrote multiple tests before writing any production code (write one at a time)

## Output

After completion, show:
- How many RED-GREEN-REFACTOR cycles completed
- All passing test names
- Files created/modified
- Any remaining edge cases not yet covered

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [huzaifa525](https://github.com/huzaifa525)
- **Source:** [huzaifa525/claude-code-optimizer](https://github.com/huzaifa525/claude-code-optimizer)
- **License:** MIT
- **Homepage:** https://www.npmjs.com/package/claude-code-optimizer

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-huzaifa525-claude-code-optimizer-tdd
- Seller: https://agentstack.voostack.com/s/huzaifa525
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
