tdd
Write the test before the code. The loop runs red, then green, then refactor, and the loop is mandatory. Order carries the discipline: a test written first fails for a real reason and pins behavior the code lacks. Written after, a test ratifies whatever the code already does.
Each phase ends on a condition the test gate can observe, so the gate enforces the loop. The deep mechanics (sizing a step, the false red, where TDD does not fit, a worked example) live in tdd practice.
Steps
-
Frame the next behavior. State one observable behavior the change must add: this input yields that output, or this call produces that effect. A bug fix frames the behavior as the defect reproduced. The step is framed when the behavior is a single fact specific enough to pass or fail without judgment.
-
Red: write one failing test. Write a single test for that behavior, asserting the output or the observable effect, never the internals. Run
skill-gate --category test. The step is done when the gate reports one new test failing, and the failure message names the missing behavior rather than a syntax or import error. See the false-red trap in tdd practice. -
Green: write the least code that passes. Write the minimum production code that turns the bar green, adding nothing for a behavior no current test demands. Run
skill-gate --category testagain. The step is done when the full suite is green, with no test skipped or commented out. -
Refactor: improve the design on green. Improve naming and structure, and remove duplication, while behavior stays constant. Never reshape a red suite: a red suite cannot tell a safe change from a breaking one. Run
skill-gate --category testonce more. The step is done when the suite is still green and no observable behavior changed. -
Harden the change. Run
skill-gate --category lint, thenskill-gate --category types. The step is done when both commands exit zero. -
Advance or close. Per remaining behavior, return to step 1 with the next one. The change is done when every framed behavior has a green test and steps 2 through 5 have each reported their completion criterion.
See also: the foundation doctrine.