A Test-Driven Mentality

Tests still come first in your approach to legacy code. You will need to write tests to characterize existing behavior, even though these tests cover code already written. You will also test-drive any new code you write.

You’ll likely realize that writing tests after the fact (something I refer to as Test-After Development [TAD]) requires considerably more effort than had you created the code using TDD. The primary reason is that programmers don’t structure their code to be easily tested if they’re not worried about testing it. The second reason is that when test-driving, you should be continually factoring toward smaller, more reusable elements that make the crafting of new tests and code easier.

Testing the open function ...

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.