Tdd

From softspark/ai-toolkit · View interactive version

Tdd is an AI agent skill from the GitHub repository softspark/ai-toolkit. TDD with red-green-refactor loop and vertical slices. Triggers: TDD, test-first, red-green-refactor, test driving development.

How to use this skill

Skill file

Test-Driven Development

$ARGUMENTS

Build features using strict RED → GREEN → REFACTOR cycles with vertical slices.

Usage

/tdd [feature or behavior to implement]

The Iron Law

NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST

Write code before the test? Delete it. Start over.

No exceptions:

Implement fresh from tests. Period.

Violating the letter of this rule is violating the spirit of this rule.

Philosophy

Core principle: Tests verify behavior through public interfaces, not implementation details. Code can change entirely; tests shouldn't.

Good tests: Integration-style, exercise real code paths through public APIs. Describe _what_ the system does, not _how_. Read like specifications. Survive refactors.

Bad tests: Coupled to implementation. Mock internal collaborators, test private methods, verify through external means. Warning sign: test breaks on refactor but behavior is unchanged.

See reference/tests.md for examples, reference/mocking.md for mocking guidelines.

Anti-Pattern: Horizontal Slices

DO NOT write all tests first, then all implementation.

WRONG (horizontal):
  RED:   test1, test2, test3, test4, test5
  GREEN: impl1, impl2, impl3, impl4, impl5

RIGHT (vertical):
  RED→GREEN: test1→impl1
  RED→GREEN: test2→impl2
  RED→GREEN: test3→impl3

Tests written in bulk test _imagined_ behavior. Vertical slices let each test respond to what you learned from the previous cycle.

Workflow

1. Planning

Before writing any code:

2. Tracer Bullet

Write ONE test that confirms ONE thing:

RED:   Write test for first behavior → test fails
GREEN: Write minimal code to pass → test passes

This proves the path works end-to-end.

3. Incremental Loop

For each remaining behavior:

RED:   Write next test → fails
GREEN: Minimal code to pass → passes

| Rule | Description |

|------|-------------|

| One at a time | One test per cycle |

| Minimal | Only enough code to pass current test |

| No anticipation | Don't code for future tests |

| Behavioral | Tests focus on observable behavior |

4. Refactor

After all tests pass, look for refactor candidates:

Never refactor while RED. Get to GREEN first.

Checklist Per Cycle

[ ] Test describes behavior, not implementation
[ ] Test uses public interface only
[ ] Test would survive internal refactor
[ ] Code is minimal for this test
[ ] No speculative features added

Rules

Red Flags — STOP and Start Over

If you catch yourself doing ANY of these, delete the code and restart with TDD:

Common Rationalizations

| Excuse | Reality |

|--------|---------|

| "Too simple to test" | Simple code breaks. Test takes 30 seconds. |

| "I'll test after" | Tests passing immediately prove nothing. |

| "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |

| "Already manually tested" | Ad-hoc ≠ systematic. No record, can't re-run. |

| "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. |

| "Need to explore first" | Fine. Throw away exploration, start with TDD. |

| "TDD will slow me down" | TDD faster than debugging. Pragmatic = test-first. |

| "This is different because..." | No. Apply the Iron Law. |

Verification Checklist

Before marking work complete:

Can't check all boxes? You skipped TDD. Start over.

Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.