Skip to content
Back to skills

Tdd Workflow

ASecurity

Has the agent find the repository's own test commands, then build one behavior per cycle with one failing test, seen failing for the expected reason, the smallest code that passes it, and the full suite before the next. Use when adding or changing behavior test-first, or fixing a bug that needs a reproducing test. Not for docs, config, generated files or throwaway spikes, and not for checking code that is already written (use verification-loop). Guidance for Law 3 (One Thing at a Time) and La...

  • 11 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added May 28, 2026
ai-agentsgotestingrefactoringgitdatabasedocumentation

Security analysis

A100/100

Scanned December 5, 2026

npx -y skills add naimkatiman/continuous-improvement --skill tdd-workflow --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Tdd Workflow?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Tdd Workflow
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/naimkatiman-tdd-workflow/badge)](https://www.skillsdirectory.com/skills/naimkatiman-tdd-workflow)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: tdd-workflow
tier: "1"
description: "Has the agent find the repository's own test commands, then build one behavior per cycle with one failing test, seen failing for the expected reason, the smallest code that passes it, and the full suite before the next. Use when adding or changing behavior test-first, or fixing a bug that needs a reproducing test. Not for docs, config, generated files or throwaway spikes, and not for checking code that is already written (use verification-loop). Guidance for Law 3 (One Thing at a Time) and Law 4 (Verify Before Reporting)."
origin: continuous-improvement
---

# Test-Driven Development Workflow

One behavior at a time: a failing test, the smallest code that passes it, the full suite, then the next behavior. This skill is text you read. No hook in this plugin checks that a test came first, so the only proof is the command output you quote in your report.

## When to use it, and when not

Use it when a change adds or alters behavior a caller can observe: a new feature, a new rule on an existing one, a bug fix.

Do not use it for documentation, configuration values, generated files, formatting, renames with no behavior change, or a spike the user has said will be thrown away. If the user says "no tests for this", do the work without this skill and say in the report that no test covers it.

## Step 0: Find how this repository tests

Do this before writing anything. Read the build manifest, the README or contributing guide, the CI workflow, and two or three test files next to the code you will change. Write down four facts:

1. The test runner and how it is started here (a script or wrapper checked into the repository wins over a globally installed tool).
2. Where tests live and how they are named and structured.
3. The focused command: one test file, or one test by name.
4. The full-suite command: the one CI runs.

Never assume a command. `npm test`, `pytest`, `cargo test`, `go test ./...` and `./gradlew test` are examples of what you might find, not defaults to try.

Then run the full suite once, before any edit, and keep the result. If tests already fail, tell the user which ones before you start, and leave them alone unless asked.

**No existing suite.** Use a built-in runner when it fits the stack and project rules. Ask before adding a new dependency if the user has not authorized it. If automated proof is unavailable, document the check you can run and its limits.

Done when you can state the focused and full-suite commands and you hold the baseline result.

## Step 1: List the behaviors, pick one

Write the behaviors the request asks for as plain sentences, each one observable through the public interface: the function, endpoint, command or screen that existing callers already use. For a discount code field that might be: a valid code lowers the total, an unknown code is rejected with a message, an expired code is rejected, an empty field leaves the total unchanged.

This list is a plan. Do not write tests for all of it now. Tests written in a batch describe a guessed design, and the code is then written to satisfy the guess.

Test at the level the neighboring tests use. Do not add a new kind of test (a browser end-to-end test, for example) unless the repository already has that kind for this area or the user asks for it. Use the existing public interface when the implementation layer is delegated. Bring an unresolved user-facing trade-off back at the agreed decision point.

Done when the list exists and you have named the first behavior and the interface you will test it through.

## The cycle: once per behavior

1. **Write one test** for the one behavior, in the style of the neighboring tests. Take the expected value from the request or the spec.
2. **Run the focused command and read the failure.** Three outcomes:
   - *It fails for the expected reason:* the message names the missing behavior, such as an assertion that got the old result, or a function or field that this slice is about to add. Go to step 3.
   - *It passes:* write no production code yet. Either the behavior already exists, or the test does not exercise it (wrong target, an assertion that never runs, a mock standing in for the code under test). Read the production code to find out which. If the behavior is there, comment out the line responsible and run the test: a failure shows the test covers it. Restore the line, keep the test, and move to the next behavior. If the behavior is not there, the test is wrong: fix it until it fails for the expected reason.
   - *It fails for another reason* (syntax error, bad import, missing fixture, crash in setup): fix the test or its setup, not production code, and run again until the failure is the expected one.
3. **Write the smallest code that passes this test.** Nothing for behaviors further down the list. If you notice one you missed, add it to the list.
4. **Run the focused command** until the test passes. If it fails, fix the code. Change the test only if it contradicts the request, and then return to step 2 to see the corrected test fail.
5. **Run the full suite.** If a test that passed in the Step 0 baseline now fails, your change broke existing behavior: fix the code. Do not edit, skip or delete that test to get green. The one exception is a request that changes that behavior on purpose, and then you name the test and the reason in the report.
6. **Refactor only if needed, and only on green.** Change structure, not behavior. Leave test files untouched and rerun the full suite after each change. If a test has to change for the suite to pass, you changed behavior: undo it and give that change its own cycle.
7. **Mark the behavior done** and return to step 1 of the cycle with the next one.

If the full suite takes minutes, run the focused test plus the tests for the surrounding module in each cycle, and the full suite at least once after your last edit. Say in the report that you did this.

## What a test worth keeping is

- It exercises behavior through the public interface. It does not call private functions, count calls on internal collaborators, or read the database directly when the interface can report the result. The check: it would still pass after a rewrite of the internals that keeps the behavior.
- Its expected values come from an independent source: the request, the spec, or an example worked by hand. It never computes the answer the way the code does.
- You have seen it fail.
- It covers one behavior and its name says which. Several assertions are fine when they describe the same behavior.
- It replaces only what sits outside the system (network, clock, randomness, third-party services), the way neighboring tests already do. It does not mock the module under test.
- It has no fixed sleeps and no empty body. A test with no assertion passes without checking anything.

One example, in pseudocode, to show the second point:

```
# Passes by construction: the expectation repeats the code's own formula
expect(total(cart, "SAVE10")).toEqual(cart.subtotal * (1 - rateFor("SAVE10")))

# Worth keeping: the spec says SAVE10 takes 10% off, and 10% off 200.00 is 180.00
expect(total(cartOf(200.00), "SAVE10")).toEqual(180.00)
```

## Code that was written before its test

- **Code you wrote in this session with no test:** delete it by default, then run the cycle from step 1. A test written to fit code you can still see tends to assert what the code does, not what was asked. Delete only the lines this session's own edits added, by editing them out. Do not revert the whole file, which can discard changes that are not yours. If you cannot tell whose code it is, treat it as the user's.
- **Code the user wrote, code the user asked you to keep, or anything that was there before this session:** do not delete it. Write the test around it, then show the test can fail without the change: temporarily comment out or revert only those lines, run the focused command, see the expected failure, restore the lines exactly, and see the pass. Quote both runs. If the change cannot be disabled safely, say so and report that the test was never seen failing.

## Bug fixes

Write a test that reproduces the bug before touching the fix. It fails on the current code, showing the reported symptom. If it passes, you have not reproduced the bug: get the exact input and conditions, or tell the user what you tried. Do not fix by guess. Then make the smallest fix, run the focused test, run the full suite, and keep the test.

A bug that shows on only some runs needs more: one failing run is not a reproduction and one passing run is not a fix. Run the test 20 times and record how often it fails, find the cause (order, shared state, timing, a random seed), and write a test that fails every time before you fix it. The `ship` skill, step 3, has the full method. Do not make it pass with a retry, a sleep or a longer timeout.

## Refactoring

Refactor only when the suite is green, and do not modify tests during it. Run the full suite before and after. If no test covers the code you are about to restructure, first write tests that pass on the current code and prove each can fail by breaking the code briefly. This is the one case where a new test is expected to pass on its first run.

## Excuses you will make, and the answers

| What you will tell yourself | Answer |
|---|---|
| "This is too small to need a test first." | Then the cycle is short. A small validation rule still has an empty input and a boundary to get wrong. |
| "I'll write all the tests first, then the code." | That is the batch this skill exists to avoid. One test, one piece of code, then the next. |
| "I'll write the code now and add tests after." | A test added after passes on its first run, so nobody has seen it catch anything. |
| "The new test passed first time, so it works." | A pass before the code exists means the test is not testing the new behavior. Take the "it passes" branch of step 2. |
| "It failed, so that's red." | Read the message. An import error is not the failure you need. |
| "The focused test passes, the full suite can wait." | The full suite is how you learn you broke something else. Run it now. |
| "That failing test is unrelated, I'll skip it." | Compare with the baseline run from Step 0. If it passed there, your change broke it, so fix the code. If it failed there, you have already reported it. |
| "I can't find the test command, I'll try `npm test`." | Go back to Step 0. If the repository does not say, ask. |
| "I'll add end-to-end tests and a coverage threshold to be thorough." | Nobody asked. Match the kinds of test the repository already has. |
| "I ran it by hand and it works." | A manual check is gone after this session. The test stays. |

## Done

The work is done when your report holds this evidence, not when a percentage is reached:

- The focused and full-suite commands you used, as found in Step 0.
- For each behavior on the list: the test name, the failure message you saw before the code existed, and the pass after.
- The summary line of a full-suite run made after your last edit, quoted.
- Every test you skipped, disabled, deleted or loosened, named with the reason. Normally this list is empty.
- Every behavior on the list you did not finish, named.

Coverage is a number to look at, never a gate this skill sets. If the project already measures coverage, run its command and report the figure for the files you touched. If the project's CI has its own threshold, that is the project's rule and you meet it. Do not add a coverage tool or a threshold yourself.

For build, type and lint checks before you report, use the `verification-loop` skill. If it is not installed, run the commands the repository's CI runs for those checks and quote their output.

Eval, 2026-12-01: no difference on the primary, where 24 of 24 replies passed without this skill and 23 of 24 with it (a test command that works in the repository, every test run after the last change and a test for every requested case, or a plain edit on a documentation fix and a rename), measured on the opening plan, not on the work ([method, every reply and the limits](https://github.com/naimkatiman/continuous-improvement/blob/main/evals/tdd-workflow/README.md)).

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.