Blog Stats
  • Posts - 23
  • Articles - 0
  • Comments - 19
  • Trackbacks - 4


Unit Testing 101 - Part 1 - Why do it at all?

I'm going to be giving a talk on State & Interaction Based Testing in the very near future so as part of that effort I'd like to collect my thoughts and experiences on unit testing in general.  I think a good place to start is why I unit test at all.  And for this we need to go back into the past.  A past I think most of you probably have your own version of...

I have "fond" memories of back when I was a VB 6 programmer.  Like all programmers I sat around and wrote code.  And that was about it.  Occasionally I'd run my application to make sure things looked like they might be working but I was most definitely a programmer (as opposed to a Software Developer). 

And I hated it.  If I wasn't sitting around crossing my fingers and toes while in prayer that the application wouldn't crash during a big show & tell then instead I was rushing to fix a crash that HAD occurred during a big show & tell.  I hated the pile of crap I had created over the last 5 years that I couldn't change for fear of breaking things.  I knew I was capable of better (after all some of this code was 5 years old and hopefully I had learnt a thing or two in that time..) but every time I did improve something I usually broke something else.  I hated this whole programming thing so much that I really started to look into being an electrician.  Zapping myself daily with live current couldn't be any more painful then what I was going through on a daily basis.

So I figured that maybe a switch to a new .Net project was what I needed to turn my life around.  I figured why not?  One last try before I became Shane The Electrician.  So at this point I switched companies and started on a brand new C# project.  It was glorious.. for awhile.  By this point in my life I had enough experience to realize that my code was headed in the same direction the code I had written before was headed.  At this point the question in my head was which kind of electrician was I going to be? 

And then everything changed.. it was like magic.  I remember it clearly for it was the first time I saw JP Boodhoo weave code like a true craftsman.  I watched in amazement as he presented on "Test Driven Development & ASP.NET".  He was.. writing these things called tests?  And he was proving his code worked before he even ran it?  And then he would change things and run the tests again.  OMG a test broke and he knew exactly what was wrong because the test told him in a nice little message.  It was in a word... AMAZING.  And I realized at that moment what had been missing from my life all those years.

For me testing is a safety net.  A giant warm fuzzy blanket that when done properly holds you in its warm embrace and keeps you feeling warm and cozy as you make all those formerly scary changes to your code.  With testing in place I can look at a big nasty ugly piece of code that must have been written by an idiot (me.. yesterday) and feel safe in my ability to improve that code without breaking the entire application. 

Of course at this point you're in one of two places... Either you know exactly why I bolded "when done properly" or you are hear to learn why... For which you will need to wait till next time.


# re: Unit Testing 101 - Part 1 - Why do it at all?

Gravatar Impatiently waiting for the next installment! :-) 11/26/2008 1:50 PM | mike

# Unit Testing 101 - Part 2 - Why must we be careful?

Unit Testing 101 - Part 2 - Why must we be careful? 12/20/2008 8:52 AM | Shane Courtrille's Blog

Post a comment


Please add 7 and 3 and type the answer here:


Copyright © Shane Courtrille