Chapter 19

Test-Driven Development

“Pick a little, talk a little, pick a little, talk a little, pick, pick, pick, talk a lot, pick a little more.”

from Meredith Wilson’s musical, The Music Man!

If we replace “pick” with “test” and “talk” with “code,” the song captures the essence of Test-Driven Development: write tests and code in small, incremental, alternating steps. A test case is written first, and, in the absence of the corresponding code, the test case fails when executed. Immediately, just enough code is written so that the test case will pass. (Nota bene: “pass” means the observed outputs are consistent with the expected outputs.) As code size increases, refactoring is permitted, but all the original tests must still pass (otherwise the ...

Get Software Testing, 4th Edition 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.