Test Driven Development ? Not for the faint of heart.

10. September 2009

I started coding in C# about a year ago and almost immediately found that once I had completed a project I wanted to go back and streamline and improve it. When time allowed I started trying to do this and found that the code was very hard to verify functionality. I also found that some of my design choices were pretty novice, due to that the code was very hard to enhance. 
I got introduced to the idea of test driven development by a good friend Rob Tennyson. He presented on the topic at the Tyson Foods internal .NET user group. This peaked my interest for two reasons. One, It would allow for avoiding the novice mistakes in design and class layout. Two, it would allow for my code to have automated verification of functionality.
I set out to work TDD into my everyday process and hit several brick walls.
1. You end up making things public for testing that should not be otherwise, or putting test code into the finished product (neither is a workable solution in my book). I am using NUnit and I didn't want to have a reference to a testing package in my production code. Adding a dependency to the production code that other developers will have to deal with was not my idea of a stable codebase.
2. Being a beginner in TDD as well as C# I didn't know what I didn't know so by that lack of code and language knowledge I repeated some novice mistakes in design. Not as many as before but still a few. Some would argue that I gained knowledge and that is why I see those bottlenecks and design issues more clearly and to that my only reply is "yeah prolly".
3. Abstraction is a premium but sometimes too much work. I write a lot of small applications, an editor here, a website there. While I do work to abstract a lot of my code and provide interfaces in the right places for a small application putting in the level of seams needed for proper TDD would be building an elevator in an outhouse.
4. I found it increasingly difficult to find answers in my hunt for TDD utopia. I read several books on the subject and found that I was more often than not provided with contradictory rules to apply, or methods to use. Microsoft's "Test-Driven Development in Microsoft .NET" by James W. Newkirk and Alexei A. Vorontsov gave great baseline examples and presented the basics of TDD very well, however it fails to provide good solid base for TDD in the real world. The application that they base a lot of their examples around ignores some fairly large aspects of the TDD mindset like separation of integration testing and design testing.

With the miles behind me and a TDD utopia still nowhere in sight I have found several good ideas.

1. Kent Beck's TDD by Example is a great resource for TDD on the intermediate to advanced level.

2. Not everything needs to be designed using TDD, some things are just too trivial.

3. TDD is a design pattern, and it should be used as such. If you want automated testing use automated tests, but if you want TDD programs before one line of code is written have a test list and priority assigned to them.

I am working on a TDD project currently with Jay Smith and Rob Tennyson to write a checkers application using only TDD and having no UI or Data Layer. Building Logic first, then the UI, and finally adding a data layer to detail how to handle those real world integration concerns.

Just Remember Code like you have to support it.

C#, .NET, Productivity, Unit Testing, Design Patterns

Comments

3/11/2010 6:00:18 PM #
Hey... I'm having a bit of problem with the way your site is displaying. For some reason the text block is running into the margins. Is this just me or have you heard this from other ppl?  Just wanted to let you know in case you've been changing things recently. Thanks! Vera Sandez
3/25/2010 6:04:02 AM #
Hi there, I found your blog via Google while searching for first aid for a heart attack and your post looks very interesting for me.
3/26/2010 3:43:43 PM #
I keep listening to the news talk about getting free online grant applications so I have been searching around for the best site to get one.
3/29/2010 2:11:26 PM #
I wanted to thank you for this great read!! I definitely enjoying every little bit of it.I have you bookmarked to check out new stuff you post.
3/30/2010 2:39:50 AM #
Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information.
3/31/2010 6:13:47 PM #
Very interesting post - Might be old news, but it was news to me.
4/20/2010 2:56:47 PM #
Anuncios Clasificados Gratis en España.
4/21/2010 2:38:52 PM #
Bani pe net - Learn how to make money online
4/22/2010 8:59:35 AM #
I just cant stop reading this.  Its so cool, so full of information that I just didnt know.  Im glad to see that people are actually writing about this issue in such a smart way, showing us all different sides to it.  Youre a great blogger.  Please keep it up.  I cant wait to read whats next.
4/24/2010 5:38:12 PM #
I dont know what to say.  This is definitely one of the better blogs Ive read.  Youre so insightful, have so much real stuff to bring to the table.  I hope that more people read this and get what I got from it:  chills.  Great job and great blog.  I cant wait to read more, keep em comin!
4/25/2010 9:41:06 AM #
Love, love, LOVE this blog!  You say everything that Im thinking and more.  Youve definitely shed light on a subject that not many people can argue with.  Youre so good at getting what you want to say out there in a way thats intelligent and entertaining.  Im really impressed, man.  REALLY impressed.
4/25/2010 10:04:45 AM #
Hi i must say very nice blog.
4/25/2010 7:01:46 PM #
I think youve made some truly interesting points.  Not too many people would actually think about this the way you just did.  Im really impressed that theres so much about this subject thats been uncovered and you did it so well, with so much class.  Good one you, man!  Really great stuff here.
4/28/2010 2:08:33 AM #
I was wondering if you ever considered changing the layout of your blog?  Its very well written; I love what youve got to say.  But maybe you could a little more in the way of content so people could connect with it better.  Youve got an awful lot of text for only having one or two images.  Maybe you could space it out better?
4/28/2010 2:09:36 AM #
Voucher-world - It´s time to shop for free! Receive free giftcards for doing easy and free surveys!
4/29/2010 5:48:10 PM #
Im impressed.  I dont think Ive met anyone who knows as much about this subject as you do.  Youre truly well informed and very intelligent.  You wrote something that people could understand and made the subject intriguing for everyone.  Really, great blog youve got here.
4/30/2010 9:03:16 AM #
I am normally hunting for information. This article awareness. just want to keep tabs on