3 ms·
There are lots of good techniques for adding unit tests to an existing codebase that does not have unit tests without reorganizing everything from the ground up
by jaggederest 4y ago
There are lots of good techniques for adding unit tests to an existing codebase that does not have unit tests without reorganizing everything from the ground up. I like Michael Feathers book, "Working Effectively with Legacy Code" - his definition of legacy code is simply code that does not have tests, so the whole book is more or less about how to solve this problem.
One technique he references that I find very effective is building "firewalls" between different parts of the codebase, and then unit testing those firewalls thoroughly. This means that you can isolate a bug to one part of the system or another, and drastically reduces the surface area to look at when trying to find why there is a bug or why a test is failing.
Edit: In fact, I've seen places in your D code that use similar techniques already - maybe just giving them a name makes a big difference?
- WalterBright 4y agoI haven't read his work, but the firewalls sound like encapsulating things to reduce interdependencies, which indeed is what makes unittests feasible. The data structures that go in and out of the modules then get replaced by "mock" data structures.