Testing First Drives Design

Test-driven development, or TDD, is the counterintuitive idea that developers will improve both the design and the accuracy of their code by writing the tests before they write the code. When adding new logic to a program, the TDD process starts by writing an automated test that describes the behavior of code that does not yet exist. In a strict TDD process, new logic is added to the program only in response to a failing test.

Writing tests before code, rather than after, allows your tests to help guide the design of your code in small, incremental steps. Over time this creates a well-factored codebase that is easy to change.

Success with test-driven development starts with trusting the process. The classic process ...

Get Rails 5 Test Prescriptions 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.