Unit Testing as Bug Repellant
Nobody likes bugs, whether they are mosquitoes, black flies, spiders, or software bugs. One mosquito bite is generally mildly annoying but tolerable. Similarly with software, if your customers find a bug, it usually results in mild annoyance. Of course, there are exceptions to both: some mosquito bites can be deadly as can some software bugs. What really drives people nuts about mosquitos is the repeated exposure. Similarly what drives your customers nuts is when a bug you’ve previously fixed reappears.
When we first realize that there are mosquitoes around (this usually happens when we first get bit), what is the first thing we do? We reach for the bug spray to keeps the bugs away. Similarly, once we encounter a software bug we can use Unit Testing to keep it from returning.
Before you fix the bug create a unit test to catch it and verify that the new unit test does in fact fail. Then fix the bug and run the unit tests to verify that you did indeed fix the bug and didn’t introduce any new ones. Now that particular bug will not come back, because if you do happen to reintroduce it again your unit tests will catch it before it ships.