Chapter 5. Working with Legacy Code

Having a solid set of unit tests is critical for a successful project. As you have seen so far, not only do unit tests help prevent bugs from getting into the code, but they also help in many other ways such as guiding the design, enabling us to refactor the code and keep it more maintainable, as well as a reference where you can see what the expected behavior is supposed to be.

TDD is the best way to ensure that our code has all the properties mentioned in the preceding paragraph. But, as anyone who has worked on larger, more complex projects knows, there are always pieces of code that don't have tests. Usually, this is the code written many years ago, long before we started practicing TDD. Or, it might have ...

Get Test-Driven Python 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.