Tdd

From lexler/skill-factory · View interactive version

Tdd is an AI agent skill from the GitHub repository lexler/skill-factory. Test-driven development (TDD) process used when writing code. Use whenever you are adding any new code, unless the user explicitly asks to skip TDD or the code is exploratory/spike.

How to use this skill

Skill file

Test-Driven Development Process

TDD is a design technique that uses tests as a tool. Design emerges from usage, not speculation. Short feedback loops let you course-correct immediately. The resulting architecture is testable by design, not retrofitted. We are not trying to rush towards a feature completion, it's important that the code is correct and well-designed, it's crucial to be thorough and only add what tests demand.

When starting, announce: "Using TDD skill in mode: [auto|human]"

MODE (user specifies, default: auto)

STARTER_CHARACTER = ๐Ÿ”ด for red test, ๐ŸŒฑ for green, ๐ŸŒ€ when refactoring, always followed by a space

Core Rules

  1. ALL code changes follow TDD - Feature requests mid-stream are NOT exceptions. Write test first, then code.
  2. Write only one test at a time - focus on the simplest, lowest-hanging fruit test
  3. Predict failures - State what we expect to fail before running tests
  4. Two-step red phase:
  1. Minimal code to pass - Just enough to make the test green. If no test requires it, don't write it.
  2. No comments in production code - Keep it clean unless specifically asked
  3. Run all tests every time - Not just the one you're working on
  4. Refactor at the first opportunity when the tests are green
  5. Test behavior, not implementation - check responses or state, not method calls
  6. Push back when something seems wrong or unclear

Test Planning

  1. Think about what the code you want to write should do
  2. Plan tests as single-line [TEST] comments. Example:

```

[TEST] Zero plus a number is equal to that number

[TEST] Add two positive numbers

[TEST] Add two negative numbers

[TEST] Adds a negative and a positive number

[TEST] Division by zero is not allowed

...

```

  1. Check completeness - walk through ZOMBIES explicitly:
  1. If MODE is human, wait for confirmation after test planning

Implementation Phase

  1. Replace the next [TEST] comment directly with a failing test. No intermediate markers.
  2. Test should be in format given-when-then (do not add as comments), with empty line separating them
  3. Think through the expected value BEFORE writing the assertion. Trace the logic step by step.
  4. Predict what will fail
  5. Run tests, see compilation error (if testing something new)
  6. Add minimal code to compile โ€” empty method bodies, placeholder returns, missing classes. Do not implement logic yet.
  7. Predict assertion failure
  8. Run tests, see assertion failure
  9. Add minimal code to pass
  10. Predict whether the tests will pass and why. Run tests, see green
  11. If the test passed without ever being red, pause. Identify which earlier step added the code this test is exercising for free. Call it out (e.g., "This passed immediately because I added X at step N before a test required it"). Tighten discipline on remaining tests.
  12. Simplify. For each line/expression you just added, ask: "Does a failing test require this?"
  1. Refactor.
  1. Go to step 1 for the next [TEST] comment. Repeat until all planned tests are passing.

Final Evaluation

  1. Analyze the code written and think about the tests that we might have missed.
  2. If there are any gaps in the tests, start the process for the missing tests from the beginning, starting from test comments then following the process flow until done
  3. Is anything still hardcoded in the code that shouldn't be? Fix it, analyze test gaps and go back to previous stages if needed.
  4. Analyze code expressiveness and quality. If there's anything you can see to improve, go to refactoring phase.
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.