How to apply a bugfix

by Jason Swett,

Any bugfix job has three distinct stages: reproduction, diagnosis, and fix. This post is about the third phase, the fix.

It might seem like the “fix” phase of a bugfix is simple: just fix it. But it’s not that simple. Many people screw it up. I certainly have.

They key thing with a bugfix is that you have to have a way to be sure your bugfix actually fixed the bug. So before you apply a bugfix, devise a test (which can be a manual test or an automated test) which has the following qualities:

  • The test fails when the bug is present
  • The test passes when the bug is absent

And, crucially, perform the test both before and after the fix has been applied. If you don’t perform the test before the fix is applied, you don’t know if the test is passing afterward because your fix worked or because your test gives a false positive.

And not only is it important to make sure your test fails when the bug is present, but that it fails in the precise way you expect. If the test fails in a way other than what you expect, then it might be failing for a reason that’s irrelevant to the bug, and you can’t be sure that your test is a valid one.

By following this process, you can have a higher chance of fixing your bug just once rather than having one of more false fixes before you finally succeed.

Leave a Reply

Your email address will not be published. Required fields are marked *