What Is Test-Driven Development (TDD)?

Test-driven development, or TDD, is the practice of writing tests first before adding production code. Now you may be wondering why on earth anyone would want to do that. Isn’t it hard enough writing the code regularly and then testing it after? What could we possibly gain by doing this backwards?

Well it turns out that writing tests first helps deal with one of the devils we all need to handle in software—stress.

You see, when we write software, complexity, stress, and a sense of being overwhelmed are never far from our doorstep. And it doesn’t take much for even the simplest of tests to quickly spiral out of control and seem daunting.

TDD helps to give you focus. By starting with a single test and ignoring ...

Get The Way of the Web Tester now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.