Play@Work

Thursday, June 30, 2005

Going from Red to Green

Damn ..

Whenever you come across a bug, write a test that will reproduce that bug first.
Before you start writing one line of code to fix it make sure there is this failing test which will capture the scenario.

- Turnaround time is much faster. You can see immediately what your code is doing. The "fix-build-start app-verify fix" is just a "run test" now. Much much faster.
- The test(s) document the bug. - No chance of the bug reappearing.
- No question of laziness and not writing a test once the fix is in place. Sometimes writing unit tests is not that easy and like all good things in life, its easy to say "aww .. Let me skip writing a test this one time .. it can never break anyways"

- Going Test First tends to make your code better(generalizing I know)
- Writing a test after the fix, sometimes, does not catch some of the obscure scenarios that you fixed using some weird logic in the code.

Been bitten by this more than once.
Damn, its so easy to convince your self that you will go for that jog tomorrow .. umm I mean .. write that test later ;-)

17 Comments:

Post a Comment

<< Home