</>CodexBash
All articles
Programming

Test-driven development

Test-driven development explained with a worked example: the red, green, refactor cycle, writing the smallest failing test, triangulation, how TDD shapes design, a complete kata in Python, TDD with mocks and outside-in, when TDD helps and when it does not, and common misconceptions.

CodexBash, , 6 min read

Most developers write code first and tests afterwards, if at all. Test-driven development (TDD) reverses the order: you write a small failing test before the code that makes it pass, then improve the design, then repeat, in cycles of a few minutes. Popularised by Kent Beck as part of Extreme Programming, TDD is less about testing than about design and feedback: it forces you to decide what code should do before deciding how, keeps you working in tiny safe steps, and leaves behind a test suite that covers every behaviour you built. This article explains the cycle and walks through a complete example.

Sign in to read the rest

The whole 6 minute article is free with an account, along with every problem, lesson and tutorial. No card.