... please remember people, no matter who you are, and whatever you do to live, thrive and survive, there are still some things that make us all the same: you, me, him, them - everybody, everybody! - this is a fragment of Blues Brothers' "Everybody Need Somebody" song. Nothing to do with software development but when you change the next line of this song from "Everybody needs somebody" to "Everybody needs Unit Tests" it becomes closer to software development.
I intentionally used lyrics of this song to keep everyone's attention (just a little bit) to this post. If you are familiar with TDD and unit test your code you can disregard it - I'd like to address this post to all software engineers/developers/programmers/etc. that DO NOT unit test their code.
In this post I will try (again) to convince all software developers that still don't unit test their code that it's right thing to do and it's damn simple.
You don't have to be the fan of Agile movement - you can even think it's stupid, immature and doesn't help software development at all. Maybe you're right, maybe not - it's rather a question of taste. You don't have to use or like Scrum, you may think that XP is crazy and an overkill - you have right to think so. I can understand everything but PLEASE do unit test your code! Forget about Agile, forget about processes and methodologies - just unit test your code.
I just took over another project that is quite complex (of course it is!) but has NO SINGLE unit test (or any test at all). More so, there is no documentation of any kind. Yes I can read the code and see what it does - that's simple but how the hell I could know it does what it should do? How could I know it's not a mistake made by the developer who created this creature?
This code lacks Unit Test, but fortunately day after day I add more and more and I'm more confident this piece of software works.
If you want to know something more about unit testing check out our previous articles. I will just recapitulate the most important, in my opinion, qualities of unit testing:
I hope I convinced you to start writing unit tests - if you don't like or believe in Agile movement it's OK. Unit Testing is just an obligatory practice of every decent software developer. If you do unit test it doesn't mean you're good one but if you don't unit test you're a poor developer (I mean it).
I wonder when unit testing will be taught obligatory at every decent university. It does so many good and is so simple - people, please - write unit tests!
If you have any ideas how to convince every developer that unit testing is right thing to do I'm open for suggestions.
Comments
Test what you don't prove.
February 5, 2009 by Ricky Clarkson (not verified), 1 year 5 weeks ago
Comment id: 2215
Test what you don't prove.
unit tests have other uses too
February 5, 2009 by Anonymous (not verified), 1 year 5 weeks ago
Comment id: 2216
Another great use for unit tests is for isolated performance profiling or (in C++) memory leak detection using tools like purify, valgrind, or what-have-you. When working with server code it is may be difficult, or at least time-consuming, to bring the server to the state where performance profiling or leak detection should start. With unit tests it is much quicker, which allows you to test changes out much more quickly than would be the case if you had to relink the server, restart it, and bring it back to the state where testing should begin.
Further reading
February 6, 2009 by Tiago Fernandez (not verified), 1 year 5 weeks ago
Comment id: 2217
For those who are still not convinced about TDD:
http://blog.jayfields.com/2009/02/thoughts-on-developer-testing.html
Unit testing is not simple
February 6, 2009 by jackMilunsky, 1 year 5 weeks ago
Comment id: 2218
All of the benefits you mention are 100% accurate. I cannot emphasize enough just how important unit tests are. You cannot be agile without an agile codebase. Unit tests along with well written and designed code keep your codebase agile and give your business options.
I disagree that Unit Testing is easy, it's not really. No pain no gain is what I say.
We strive for 100% code coverage and would never consider doing it any other way. Although 100% is debatable as to whether that's over-kill.
My 2 cents,
Jack
www.agilebuddy.com
blog.agilebuddy.com
Thanks all for your valuable
February 6, 2009 by pbielicki, 1 year 5 weeks ago
Comment id: 2219
Thanks all for your valuable comments - I appreciate it.
@jackMilunsky - I would use double standards here - say your employer or prospective employer during interview that unit testing is sometimes a difficult art but we have to encourage other guys by selling them basics (which are simple) - they will learn more advanced stuff later on i.e. step by step
Cheers!
Re: Better Design
February 12, 2009 by andhapp (not verified), 1 year 4 weeks ago
Comment id: 2228
Unit test gives you a better design. It gives you a decoupled system or it atleast points out where the code is coupled and in order to unit test you have to break it down into smaller modules. Unit Testing implies better design.
Post new comment