What is Test-driven development?
Test-driven development (TDD) is a practice where you write a failing test for a small piece of behaviour first, then write just enough code to pass it, then clean up. The tests come before the code, which keeps the design honest and the safety net thorough.
Read in RomanianTest-driven development
Why it matters
Tests written after the fact tend to test what the code happens to do. Tests written first describe what the code should do, and you end up with a suite that actually catches regressions.
In practice
The loop is red, green, refactor: a failing test, the smallest code to pass it, then cleanup with the test as a safety net. It is a discipline, not a religion; use it where the behaviour is worth pinning down.