Test-Driven Development
Writing a failing test first, making it pass, then improving the code with the test as a net.
Test-driven development is the practice of writing a failing test before the code that satisfies it, then writing the minimum implementation to pass, then refactoring with the test as protection. The cycle is usually named red, green, refactor.
The red step is the one that carries the value, and it is the one most often skipped. A test written after the implementation and added to a passing suite has never been observed to fail, so it might be asserting nothing at all — see Falsifiability. Writing it first makes the failure a precondition rather than a hope.
The secondary benefit is design pressure. Code that is hard to test from the outside is usually code with tangled dependencies or unclear boundaries, and the friction shows up before the design has calcified.
The main misuse is treating it as a mandate to test every function in isolation. Tests bound to internal structure make refactoring expensive — the suite breaks when the implementation changes even though behaviour did not, which trains people to distrust it. Favouring tests at the seams that outlast implementations, and integration over unit tests on private helpers, keeps the suite an asset rather than a tax. See Integration Test.
See also4
Hand-picked in the note itself — the neighbours worth reading next.
Unit Test
A fast, isolated test of one unit of behaviour with its collaborators replaced.
Testing & Verification11 connections
Assertion
The statement in a test that must hold, and the only part that can actually fail.
Testing & Verification9 connections
Regression
A previously working behaviour that a change has broken.
Method16 connections
Code Coverage
The proportion of code executed by a test suite — a map of what is untested, not a measure of quality.
Testing & Verification12 connections
Related3
Nearby in the graph rather than deliberately chosen. Looser, sometimes surprising.
Linked from5
Notes elsewhere in the wiki that reach for this one.
- AssertionTesting & Verification
The statement in a test that must hold, and the only part that can actually fail.
- Code CoverageTesting & Verification
The proportion of code executed by a test suite — a map of what is untested, not a measure of quality.
- Integration TestTesting & Verification
A test exercising several components together, through real interfaces rather than doubles.
- Tree ShakingWeb Platform
Statically removing exports that nothing imports, shrinking the shipped bundle.
- Unit TestTesting & Verification
A fast, isolated test of one unit of behaviour with its collaborators replaced.