Friday, May 09, 2008

Survey Says: Unit Testing Still Not Mainstream

Another survey and another set of interesting results. For the last couple of weeks I've been running a survey on this blog asking you to indicate if you use unit tests A) pretty much all the time, B) once in a while, or C) never. And within the last option, I gave you the opportunity to indicate if you're not using unit tests because you don't know what they are or because simply don't think you need them. Clearly, I expected a large number of you, dear readers, to fall in to categories A and B, but just as with the "why do you code" survey, you've surprised me.

Frankly, I'm still trying to decided whether these results represent humor responses or painfully honest feedback. I find it hard to believe that in this day and age of TDD and Agile buzzing all around that you can escape knowing what unit tests are. Still, 9% of you indicate that is the case, so clearly it is possible. More shocking than not knowing about unit tests, though, is the large group of respondents that said they know about unit tests but don't think they need them! Almost 40% of those that answered fell in to this category.

That raises the most interesting follow-up question: Why don't you think you need unit tests? Clearly their benefits are well extolled across the interwebs, so it shouldn't be necessary to point out how unit tests help you write better, more maintainable code. Knowing that, though, many of you still (apparently) rely on manual testing. Are unit tests still to hard to integrate in to your programming work flow? Do you generally write perfect code ([cough]...liar)? Sound-off in the comments and let us know.

And just to be clear and set the tone, I don't unit test all of my code (not nearly to the degree I know I should). Largely it's because I'm a web developer and I've always found it too hard to create unit tests for code that spends most of its time reading or updating databases. How much does a unit test help when you start mocking everything out? Still, I'm getting better and I increasingly depend on unit tests for writing better code.

Regardless of your answer, thanks to everyone for participating in another survey. The next survey is already up, and with summer approaching, I'm asking how often you manage to leave the computer and spend some time outdoors. As always, be honest.


Anonymous said...

I tend to code in a style referred to as the "anaemic domain model". So Dao, Managers, Service etc. The problem is that I never know how to Unit Test the DAO's and therefore don't do it at all. If I could just find that one good example ... :(


Todd Anglin said...


I know the feeling. I used to feel the same way. I'm trying to get past that fear of DAO testing with the aid of TypeMocks, so once I'm comfortable with the process I'll be sure to post some tutorials. Hopefully you'll find them helpful!


Anonymous said...

Though I have been using Unit testing for a while I never found great value in them. The purpose of any unit testing framework I believe is to have a very low density of defects. But most of the time the Junit test creation exercise was a mere formality to avoid being caught by some code coverage tool. For all practical purposes manual QA testing helps us more in ironing out bugs and gives greater level of confidence. Again Junit testing does not have proper answers when it comes to database. Most of the solution is to mock but it is really not a great solution considering there is such a huge dependency on databases in every modern day application.
Maybe I am not getting the unit testing plans right but based on my experience till date i feel its overrated