Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at
My Unit Testing Challenge

Objects I've always thought of myself as a decent programmer.  I'm able to find solutions for people and I get rave reviews on how great something works.  However, there's always been a part of me that knows that I can program it better using agile methods and sound fundamentals.

I haven't taken the time to implement unit testing in my application because of time constraints.  It's been one of those things that has always left a sour taste in my programming mouth.  For an application that spans 300 pages, 200 controls and 100 Controller Modules, you'd think that I'd have a better handle on the code and a testing plan in place.

nunitInstead of automated testing, we have our QA team go through printed scripts (some over 200 pages).  Some of the site is still undocumented and we do not have a formal testing plan, so we have to remember to test it out before it's sent to the customer.  As a rule of thumb, we've always set aside double the time we estimate for programming.  Not the most efficient way to estimate, but it's worked for us in the past.  We've gotten to the point in a program that it is no longer practical.

Why am I able to get away with this?  I am the architect.  I am involved from the kickoff to the deployment.  I am creative control.  I can tell you in 30 seconds whether or not a certain feature exists.  If something doesn't work properly, I'm the one to fix it.

The solution to this is putting in unit tests for all of the code in the site.

Jeremy Miller from CodeBetter is a proponent of Unit Testing and Agile methods.  He says in his Programming Manifesto:

"An axiom of software development is that problems are cheaper to fix the sooner that the problems are detected.  If you take that axiom at face value, it's easy to see why I put far more weight into comprehensive test-first unit testing because it gives you far more rapid feedback to find problems fast.  Small, isolated unit tests work on very granular pieces of the code, so the number of variables in any single unit test should be small (if it's not, look for a different way to write the code).  You shouldn't even try to run the code as a whole until all the constituent pieces have been validated through unit tests."

This is very easy to build if you are starting a new project.  What do you do if you have a large, enterprise-sized project that has no unit testing?  You start out with your business layer and build from there. Start with a small method, then you can build up from each class. 

I worry about trying to get the Lexus when I'm only looking to build a Kia.  I want everything to be perfect when I've gotten something to the point of "release ready".

When Jeff Atwood (Coding Horror) started posted about formal unit tests, he was struggling to find the "perfect test":

"You'll get no argument from me on the fundamental value of unit testing. Even the most trivially basic unit test, as shown in the code sample above, is a huge step up from the testing most developers perform-- which is to say, most developers don't test at all! They key in a few values at random and click a few buttons. If they don't get any unhandled exceptions, that code is ready for QA!"

So I start by building small tests and work from there.  It may take a long time to fully implement unit tests, but I believe this will be to our advantage in the end.

I offered this solution of adding unit tests and GUI automation to my boss.  He seems to think that this will add significant time to programming and it won't be practical.  The real problem that he doesn't trust that the interface will get a thorough testing.  I told him that there are ways to get this working (possibly using InCisif or WatiN) that would be just like one of the QA team.  He really just can't see how it will work for us. 

I don't know how I can explain to him that it will end up in his best interest (and mine) to add the unit tests for the business layer and for the GUI.  If not, I guess I'll just have to revert back to programming using BDD.

Posted 10-23-2007 4:02 PM by Stephen Wright
Filed under:



My Unit Testing Challenge - Stephen Wright « Noocyte’s Weblog wrote My Unit Testing Challenge - Stephen Wright « Noocyte’s Weblog
on 10-24-2007 7:06 AM

Pingback from  My Unit Testing Challenge - Stephen Wright « Noocyte’s Weblog

Derik Whittaker wrote re: My Unit Testing Challenge
on 10-24-2007 8:01 AM


I have been in a very similar situation in the past.  The one difference i had was my boss thought tests were a good idea, but that was just talk.  He would never state that they were required or even desired.

However, i knew that without the tests we would be in a world of hurt at somepoint in the future.  The one thing i did to get tests into the system was:

1) Start testing all new code first

2) Spent about 15-30 minutes each day at the start of my day adding a few tests.

3) When we had down time (between releases, during qa, etc) i would refactor and add tests.

Tthese are slow going at first, but over time as the test suite fills out and they prove their worth, you will find more time for writing them.

My 2Cents.

Joe Ocampo wrote re: My Unit Testing Challenge
on 10-28-2007 10:34 PM

You may want to tell your boss about the decrease in maintenance cost he will incur by adopting a test first approach.  The return on investments is significant from a project estimation and developer confidence perspective.  

Draw parallels between debt and lack of test coverage.  

Like all debt the interest that occurs overtime exponentially out ways that of enhancebility since the development team ultimately ends up with an unstable system afraid of changing code.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)