Geeks With Blogs
Jamie Kurtz Promoting architectural simplicty

I have a small confession to make...

A little TFS web service I built over the past few days was the first “real” production-ready application I’ve ever written from scratch where I’ve been good about maintaining unit tests. I even pushed myself to practice real-live TDD, and then even use Moq.

I have to tell you, that I am now a firm believer in the benefits of leaning very heavily on your unit tests. Of course I've always believed others' stories, and have even worked on projects/products where I had to maintain a fair set of tests. But not having ever really tried it myself – on a new project where I could create real isolated unit tests, I think my belief was kind of shallow. Sort of like… believing that the life vest will save your life before every really needing it. And then one day you find yourself involved in a boating accident and you awake after being unconscious in the water for two hours. Then you REALLY believe it.

I think this small experience will help me in conveying to others the incredible importance of building that unit test base. Because after only a few tests were written (and hence, only a bit of code written), I found myself getting nervous (as usual) making changes. But then I could flip to the Visual Studio Test View, run all the tests, and feel some assurance that I wasn't totally hosing things. Then as bugs would crop up during user acceptance testing, the very first thing I would do is write a new unit test that I knew would fail – based on the conditions I saw in the UAT. Then I would proceed to change the code until the unit test passed. What a great feeling!! And further, I know that anyone else making changes to my code will have to pass all the same unit tests – another very assuring feeling.

It really is amazing how much we screw up in code!?!?! Even the stupidest littlest things. There were times when I would think "This is lame, I don't need a test. But I'll write one anyway - and I'll write it before I even write the code." And then it would literally take me three or four tries to get the test to pass!! Crazy. Makes me very scared about all the untested code churn going on in the world!!

Oh, and using Moq was a real treat - it only took me a few unit tests to get the hang of it. Really helps reduce the time feedback cycles during development - as well as help in isolating your tests to smaller and smaller units (i.e. "unit tests").

Posted on Tuesday, February 24, 2009 8:43 PM | Back to top

Comments on this post: Small Confession

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Jamie Kurtz | Powered by: