What is legacy code?
In this chapter, we will use the term legacy code to mean any code that does not have unit tests. This is a rather broad definition, since it includes the code that was written long ago as well as recent code, which, for some reason, was written without tests. Although not strictly about the old code, this is a popular definition in the TDD community, made mainstream by Michael Feathers' excellent book Working Effectively with Legacy Code (Prentice Hall, 2004), and this is the meaning we will adopt in this book as well.
There are five steps to working with the legacy code:
- Understanding the code: If we are lucky, we will have some great documentation that will help us understand the code that we are going to touch. More likely, documentation will be scant or not present altogether. Since there are no tests, we cannot read the tests to try to understand what the code is supposed to do. And for really old code, chances are that the person who wrote the code does not...