8.5 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access