Working with legacy code (again)

I’ve been working on the hairball project again - we’re nearly done now - deleted half the classes in the source tree the other day. A good feeling!
If I was starting it from scratch, this is how I would do it:

  • Write integration tests that treat the project as a black box
  • Don’t refactor *
  • Don’t delete functionality *
  • Do add methods to trigger the black box functionality
  • Write lots of coarse grained tests - ‘I do a trade on the market and this record appears on the database’

*well, not yet - wait until the tests have good coverage.
The utility classes that you use to help write the tests become implementation classes for the new system.
It’s a kind of top-down agile - using Integration Tests to capture the current system’s functionality and reverse engineer its implementation. And like normal bottom up agile, if it isn’t in the Integration Tests then it isn’t a visible part of the system, so you can ditch it.

Leave a Reply