Write Your Tests First...Because Adding Them Later Sucks

Seriously. Right now I'm trying to add tests around a section of code that doesn't have any, and it's not fun. Why? Here's a couple of thoughts that spring to mind:

  • It's boring. Write the obvious tests. Check code coverage - what did I miss? Write more tests capturing more edge cases. Wash, rinse, repeat. Ugh.
  • It's not trivial. I'm trying to put tests around code that was created months ago, and trying to capture the mental state of the coder and what he was doing is damn near impossible.

Write your tests first, or at least write them in conjunction with your new code. I find that it's so much easier to have your tests in place with new code rather than trying to bang out tests with untested code that's been around for a while. In the end, having tests is better than having no tests (assuming the tests are good ones) but don't wait to write them until it's too late.

* Posted at 12.10.2007 08:56:13 AM (Last Update: 12.11.2007 08:59:48 AM) | 1 comment | Link | RSS *

Comments

# yep, from mike h at 12.11.2007 08:59:44 AM

Not to mention that your code will probably improve as you test it. A lot of times I change something in my code after I test it because a) I learn something about how my code executes or b) I learn through code coverage what I can prune off.

Add a Comment

(*) = Required field
Name (*):

E-Mail (*):

Web Site:

Title (*):

Comments (*):

Enter the code you see (*)



Quote
"'Let There Be Light' - and they watered down the beer." Anonymous
Twitter History
follow me on Twitter
Blog History