Shaf Lab

Test-driven development

Write a failing test, then the code that makes it pass, often called TDD.

Test-driven development, or TDD, is the habit of writing a failing test first, then the code that makes it pass, and then a cleanup pass — the red-green-refactor loop. The test is a specification the runtime can check. When an agent is writing the code, that loop is especially useful, because the agent can see a concrete failure instead of guessing whether it is done.

The tests that work best here are small, deterministic, and close to the behavior you care about. A test that needs a full browser and a sleep is a weak red. A test that names one invariant is a strong one. After the test goes green, you or the agent should still tidy the code; a passing test is not a license for a messy change.

Do not pretend every change wants a full TDD ceremony. A typo, a pure config edit, or a spike can skip it. Use the loop when you are adding behavior, fixing a bug, or handing work to an agent that needs a finish line.

Keep the tests in CI so a later change cannot quietly break the contract. If an agent cannot run the tests, it is not really doing TDD — it is only writing files.