Skip to content

Everybody Needs ... Unit Tests

February 5, 2009 by Przemysław Bielicki


Picture courtesy of Lotus72@flickr

... 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.

Assume that Agile software development is wrong, really wrong

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.

Unit Testing once again

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:

  • unit tests document internal and external architecture of the software system
  • unit tests help you and other developers to immediately see whether code "improvements" broke already existing code
  • unit tests help making your software bug-free - all issues should be addressed by writing a failing test first
  • unit tests together with code coverage tools improve quality of your software
  • unit tests can be used as a presentation platform - you can present hard to visualise issues using unit testing green bar - green means that it works
  • unit tests significantly improve team confidency in progress - if all the tests pass it means that all features implemented so far work and nobody broke the system
  • unit tests improve efficiency - you don't have to perform laborious manual tests again and again after code changes, just start unit tests and watch the red/green bar
  • already there but so important that worth reminding - unit tests work as a DOCUMENTATION (auxiliary or main one)
  • I'm open for your propositions

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.

About the Author: Przemysław graduated from Gdańsk University of Technology in 2004 having specialized in Distributed Information Systems. He worked in Lufthansa Systems, Intel Corporation in the past where he developed complex IT solutions in many Java-related technologies. In professional life he is a real Java expert holding couple of Sun Java certificates (Programmer, Developer, Web Developer) and Certified Scrum Master, of course.

Przemysław is a regular contributor to AgileSoftwareDevelopment.com and the author of "From Java to Java EE" blog. He now works as a Software Craftsman in an international company that is the leading Global Distribution System (GDS) and the biggest processor of travel bookings in the world. Contact Przemysław

Comments

Test what you don't prove.

February 5, 2009 by Ricky Clarkson (not verified), 4 years 15 weeks ago
Comment id: 2215

Test what you don't prove.

unit tests have other uses too

February 5, 2009 by Anonymous (not verified), 4 years 15 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), 4 years 15 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, 4 years 15 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, 4 years 14 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), 4 years 14 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.

So DSDM is entirely based on

March 2, 2012 by NOnn (not verified), 1 year 11 weeks ago
Comment id: 21167

So DSDM is entirely based on an interative development mindset. That means it recognizes that delivery is best structured across small. discrete intervals. in which small. discrete features are delivered. And it also calls the broader objective a project. as if an end exists and as if you can look out from the starting point and see that end. and then plan to work towards it. know when you've reached it. and then stop. sosh forfait sans engagement forfait illimite forfait sms illimite forfait mobile internet forfait bloque rio bouygues rio orange rio sfr rio bouygues rio virgin imc portabilite du numero

Unit test gives you a better

March 10, 2012 by sonymous (not verified), 1 year 10 weeks ago
Comment id: 21345

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.

ucnmzaopu fv jnvajqayk gy nsflqxdmt ce vajqayktv

Mike. I am on my second

May 22, 2012 by JennyH846 (not verified), 51 weeks 6 days ago
Comment id: 22338

Mike. I am on my second project to adapt Agile and I quite frankly feel like it is micromanagement for this current particular project. I am currently working on a gov't contract and with a total of about 22 developers and testers (broken down into multiple scrum teams) we have a software lead -> a contractor deputy PM -> a contractor PM -> gov't deputy PM -> gov't PM ->branch chief that are. in some capacity. hands on in running the project. rio orange

Unit check gives you a better

September 10, 2012 by ali (not verified), 36 weeks 22 hours ago
Comment id: 23790

Unit check gives you a better design. It gives you a decoupled process or it atleast points out where the code is 350-029 exam coupled & in order to unit check you require to break it down 350-029 practice tests in to smaller modules. Unit Testing implies better design.

Really loved reading your

November 15, 2012 by teryharryt (not verified), 26 weeks 4 days ago
Comment id: 24674

Really loved reading your blog. It was very well authored and easy to undertand. Unlike additional blogs I have read which are really not tht good. I also found your posts very interesting. In fact after reading, I had to go show it to my friend and he ejoyed it as well

Share It

reply

January 29, 2013 by jolanda (not verified), 15 weeks 6 days ago
Comment id: 26031

Awesome to view about this. This is certainly fairly helpful I have got It's my job to love examining the information. Properly, I appreciate you for showing.
jolanda

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <i> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <br> <blockquote>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.

Best of AgileSoftwareDevelopment.com