One Assert per Test

You test-drive small, discrete bits of behavior into your system. With each pass through the TDD cycle, you specify behavior plus a way to verify that the behavior actually works—an assertion.

To allow a future programmer to understand the behavior you designed into the system, your test must clearly state intent. The most important declaration of intent is the test’s name, which should clarify the context and goal.

The more behavior you drive from a single test, the less your test name can concisely describe the behavior.

In the library system, a holding is unavailable when a patron has checked it out and is available once a patron has checked it in. We might design a single test focused on availability.

c7/3/libraryTest/HoldingTest.cpp ...

Get Modern C++ Programming with Test-Driven Development 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.