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 behavior did not, which trains people to distrust it. Favoring 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
Unit Test
A fast, isolated test of one unit of behavior with its collaborators replaced.
Testing & Verification18 connections
Assertion
The statement in a test that must hold, and the only part that can actually fail.
Testing & Verification14 connections
Regression
A previously working behavior that a change has broken.
Method19 connections
Code Coverage
The proportion of code executed by a test suite — a map of what is untested, not a measure of quality.
Testing & Verification14 connections
Related3
Nearby in the graph rather than deliberately chosen. Looser, sometimes surprising.
Linked from6
- AssertionTesting & Verification
The statement in a test that must hold, and the only part that can actually fail.
- Cargo CultMethod
Imitating the visible form of a practice while the mechanism that made it work is absent.
- 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 behavior with its collaborators replaced.