Wednesday, April 6, 2011

Bug fixing TDD-style

So some code I wrote resulted in a bug. This is a natural part of software development of course. I'm reminded of that famous programming quote

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

The standard suggests we introduce a bug every 10 lines of code we write and I knew a programmer who could actually introduce a bug without writing anything ;)

So, how will I address this bug? Well, here is an oh-so-simple process that I follow.

1. Write a failing Unit Test that proves the bug
2. Fix the bug
3. Watch the test pass and smile

By writing the failing unit test first that recreates the bug, you are improving the unit test suite. You are also preventing that bug from happening again - you are closing the loop on it.


No comments:

Post a Comment