Skip to content

skillTesting

TDD Workflow

Builds a feature in small red, green, refactor cycles, with one failing test first and one commit per cycle, so every step stays verified.

npx workspacetemplates add tdd-workflow --tool claude-code

Writes 1 file to .claude/skills/tdd-workflow/

.claude/skills/tdd-workflow/SKILL.md29 lines · 1.8 KBFile
---
name: tdd-workflow
description: Builds a feature in small red, green, refactor cycles, with one failing test first and one commit per cycle, so every step stays verified.
---

# TDD workflow

Write a failing test, make it pass, clean up, commit. Repeat in small steps.

## Steps

1. Restate the feature as a list of behaviors, smallest first, in plain sentences. Show the list and start at the top. Find the project's test command and run it once to confirm the suite is green before you begin.
2. Red: write one test for the next behavior only. Name it as a sentence ("rejects an order with no items"). Run it. It must fail, and for the right reason: an assertion, not a typo or import error. If it passes, the behavior already exists; skip to the next.
3. Green: write the simplest code that passes, even if it looks naive (a hard-coded return is allowed for the first test). Run the whole suite.
4. Refactor: with all tests green, remove duplication, improve names and extract functions. Run the suite after each change. Do not add behavior here.
5. Commit with a message that states the behavior: `Reject orders with no items`.
6. Pick the next behavior. Prefer cases that force the code to generalize: another example, an edge, an error.
7. Stop when the list is done, then run lint and types, and review the tests for gaps: boundaries, invalid input, failure paths.

## Rules

- Never write production code without a failing test that requires it.
- Never edit a test to make it pass unless the requirement changed, and say so.
- If one cycle takes more than about ten minutes, the step is too big. Split it.
- Test behavior through the public interface, not private functions.

## Report

The behavior list with a checkmark each, the commits made, and any case you chose not to test.

What it does

Writing the tests after the code lets the tests describe whatever the code happens to do. This skill flips the order: state the next behavior as a failing test, make it pass with the least code, then tidy up with the tests as a safety net.

The agent works in tiny steps and commits after each cycle, so the history reads like a log of behaviors. If a step grows large, it stops and splits it rather than writing a pile of code first.

Example

you › Use TDD to build a function that applies a promo code to a cart total.

agent › Behaviors: 1) unknown code leaves total unchanged, 2) percent code reduces total, 3) fixed code never goes below zero, 4) expired code rejected, 5) one code per cart. Completed 5 cycles and 5 commits, 11 tests, all green. Refactored the discount lookup into a table after cycle 3. Not tested: stacking with gift cards, since the spec does not say.

Questions

Does this work on an existing codebase?
Yes, for new behavior and bug fixes. For untested legacy code it first adds a test that pins the current behavior, then proceeds in cycles.
Why commit after every cycle?
Each commit is a verified state. If a later step goes wrong you can return to the last green one, and reviewers can read the design as it formed.
  • Contract Testing

    SkillTesting

    Free
  • E2E Test Design

    SkillTesting

    Free
  • Flaky Test Diagnosis

    SkillTesting

    Free