Posted by Garry Shutler in Unit testing
You wouldn’t want a surgeon replacing your organs without some way of knowing if he had made a mistake would you? That’s why you’re hooked up to a bunch of monitors. They’ll know the instant something goes wrong and can make educated guesses about what caused that problem.
It is exactly the same for your code.
If you don’t have a suite of unit tests giving you a reassuring green beep as you refactor a section of your system, can you really be sure that you haven’t made a fatal error?
The same analogy holds for complex changes to your system. A surgeon may well be able to remove an appendix without your vital signs being monitored; the same as you can extract the odd method. But would they even attempt heart surgery without them? Can you be sure that in altering or replacing a fundamental section of your code that you haven’t introduced problems?
A suite of unit tests give you the reassurance that any changes you made have not broken the system. This reassurance turns into confidence that enables you to make the occasional sweeping change that can dramatically improve your system; either in terms of performance or maintainability.