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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.