Working Effectively with Legacy Code This book offers start-to-finish strategies for working more effectively with large, untested legacy code bases Michael FeathersJuly 01, 2019 - 244 words - 2 mins Found a typo? Edit me
What is legacy code?
Legacy code is simply code without tests.
Benefits of tests
Behavior is central to understanding the benefits of testing:
Behavior is the most important thing about software. It is what users depend on. Users like it when we add behavior (provided it is what they really wanted), but if we change or remove behavior they depend on (introduce bugs), they stop trusting us.
How to get tests in place in legacy codebases
When we change code, we should have tests in place. To put the tests in place, we often have to change code.
The suggested approach:
- Identify change points.
- Find test points.
- Break dependencies.
- Write tests.
- Make changes and refactor.
Another useful term is a “seam.” A seam, in this context, is “a place where you can alter behavior in your program without editing in that place”. The analogy is to a seam in clothing, the place where two parts are stitched together. In software, these places are generally places where there are well-defined interfaces. This can be leveraged to change the implementation using techniques such as dependency injection or mocking interfaces in the case of writing tests.