Sandro Mancuso – Testing and Refactoring Legacy Code
Working with legacy code is tough: no tests, no documentation, and fear of breaking other parts of the code. The only way to deal with that is to test and refactor merciless.
For the majority of us, legacy code is part of our life and learning how to embrace it can make things far more enjoyable. In this live coding session, Sandro will be demonstrating how to overcome the most common problems found when testing legacy code.
He will be taking a piece of messy Java code, test it until is 100% covered and then show how to refactor it in order to bring the business language and requirements to life.
This session is full of tips and tricks you can start applying immediately. Although the code is in Java, the same principles can be applied in any language.
The session starts with a quick two-minute explanation of the problem and how to tackle legacy code in general. I then immediately start coding.
In the first half I’ll demonstrate how to test legacy code, dealing with Singletons and static calls. I also demonstrate how I like to read my tests and how to create a builder to make data creation more readable.
In the second half, once the code is fully covered by tests, I start refactoring.
During refactoring I talk about feature envy and move behavior around. I show how to deal solve design issues. During the entire refactoring, I emphasize the importance of staying in the green as long as possible.
I do the entire refactoring without going into the red (failing tests) a single time. Throughout the session, I also commit many times using git, showing the importance of working in small steps.
Overall, this session can give people a good idea in how to follow some good practices at work.
What will you learn?
Good practices for testing, refactoring, and design; how to work in small steps and, most importantly, be able to test almost any type of legacy code.
Be able to read basic Java
Do attendees need a laptop?