test-driven-development
npx machina-cli add skill a5c-ai/babysitter/test-driven-development --openclawTest-Driven Development (TDD)
Overview
Write the test first. Watch it fail. Write minimal code to pass.
Core principle: If you did not watch the test fail, you do not know if it tests the right thing.
The Iron Law
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
Write code before the test? Delete it. Start over. No exceptions.
RED-GREEN-REFACTOR
- RED - Write one failing test showing desired behavior
- Verify RED - Run test, confirm it fails for the right reason
- GREEN - Write simplest code to pass (YAGNI)
- Verify GREEN - Run test + full suite, all must pass
- REFACTOR - Clean up while keeping tests green
- COMMIT - Frequent small commits
Red Flags (STOP and Start Over)
- Code before test
- Test passes immediately
- "I'll test after"
- "Too simple to test"
- Rationalizing "just this once"
Agents Used
- Process agents defined in
test-driven-development.js
Tool Use
Invoke via babysitter process: methodologies/superpowers/test-driven-development
Source
git clone https://github.com/a5c-ai/babysitter/blob/main/plugins/babysitter/skills/babysit/process/methodologies/superpowers/skills/test-driven-development/SKILL.mdView on GitHub Overview
Test-Driven Development (TDD) starts by writing a failing test that encodes the desired behavior, then writing the minimal production code to pass. The core principle is that production code should not exist without a failing test first. It follows the RED-GREEN-REFACTOR cycle and encourages frequent small commits to safeguard quality.
How This Skill Works
TDD uses a strict RED-GREEN-REFACTOR loop: RED (write a failing test), VERIFY RED (confirm the right failure), GREEN (write the simplest code to pass), VERIFY GREEN (run the full suite), REFACTOR (clean up while keeping tests green), and COMMIT (frequent small commits). The Iron Law enforces NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST.
When to Use It
- When starting a new feature or user story
- When fixing a bug to capture the exact failing behavior
- When changing an API or contract to ensure it’s tested first
- When refactoring a module to improve design without changing behavior
- When adding regression tests for known edge cases or flaky paths
Quick Start
- Step 1: Write one failing test showing the desired behavior
- Step 2: Run tests to verify the failure (RED)
- Step 3: Implement the simplest code to pass, run full tests, refactor, and commit frequently
Best Practices
- Write the failing test first that encodes the desired behavior
- Run the test to verify the failure before coding
- Implement only what's necessary to pass (YAGNI)
- Run the full test suite and refactor while keeping tests green
- Commit frequently in small, focused changes
Example Use Cases
- Creating a new feature by failing a test first, then implementing
- Bug fix with a reproducer test that fails until the fix is applied
- API evolution with tests that lock in the new contract
- Refactoring a billing module with preserved behavior via tests
- Adding regression tests for a flaky integration path