Unit Testing: Worth the Extra Effort?

January 5th, 2012 Leave a comment 3 comments
Like the article?
Unit Testing

In the realm of computer programming there are several ideas involving the testing and vetting of code to make sure it is ready to use. Many of these ideas are evolutions of previous methods or are new ways that people have developed to test code while it is being developed. One of these methodologies is called Unit Testing.

Unit Testing is part of a greater software development methodology called Test Driven Development. In Unit Testing, the code is broken down into to small sections or sub-sections called units. These units then have independent tests created that are designed to make sure that particular unit of code meets design, tests for bugs and works per the specifications. This method isolates different parts of the code and ensures that each piece works regardless of the other pieces.

There are several up-sides to Unit Testing: by isolating the unit pieces from the rest of the system you can make changes to the different pieces and test that the changed code is working correctly before you have to look at the repercussions on the rest of the system. This creates and facilitates change in the code and helps when making revisions to a large code-base. Getting your developers to begin thinking in a test-driven way can get them to create better code since they are continuously thinking about breaking it. Unit Testing also gets your developers to begin evaluating all of the requirements that the code must meet up-front instead of just jumping in to find out later the code needs to be changed to meet all of the specifications. As you can see, these are all good things that will ultimately help you end up with better-developed code.

Unfortunately, the number of developers that actually support Unit Testing in their development is small. Why? Well, Unit Testing sounds great on paper but in practice it can take a large amount of time and effort. Programmers have to create the Unit Tests as well as the code they are testing. Since Unit Tests are best written by the programmer that wrote the original routine, this can place a large work-load on a developer that may only have a short time-frame to complete their portion of the project. The key to Unit Testing really seems to be management support. Since Unit Testing is only as effective as the effort that is put into it, managers and project leads should realize that programmers need adequate time to write the code and the tests as well as fix any issues that arise in testing. Performing Unit Tests with a mediocre effort, inadequate time or only a partially through a project doesn’t do anyone any good.

Unit Testing and other methods of Test Driven Development can be worth the extra effort if care is taken to do them right from the beginning. Managers and administrators should use these tools as more than buzz-words for executives and show the benefits that the extra time can give. Unit Testing usually leads to the code needing less time with Quality Assurance/Testing departments, less time testing in beta environments and less support requests that need to be handled.

Ultimately, a good set of Unit Tests are like a shield for your code-base. You should maintain them, protect them and cherish them; they are the ones that will protect you and your code from previous errors, bugs and nasty situations. As your library of Unit Tests grow, you will begin to see how much your code writing has improved as well as the quality of your product from the process, and you will have a very valuable tool to help you with your continued development.

Help us spread the word!
  • Twitter
  • Facebook
  • LinkedIn
  • Pinterest
  • Delicious
  • DZone
  • Reddit
  • Sphinn
  • StumbleUpon
  • Google Plus
  • RSS
  • Email
  • Print
Don't miss another post! Receive updates via email!

3 comments

  1. Manu PK says:

    Good Point. I think Unit test are important and will be more useful in the rule based applications. When you are doing a CRUD based system i don’t see much value in the Unit test. I have written about this in my blog you can read it @ http://jyops.blogspot.com/2011/11/when-to-replace-unit-tests-with.html

  2. ToddRun says:

    “Unfortunately, the number of developers that actually support Unit Testing in their development is small. Why?”

    Because there are a lot of unprofessional developers in the world. Developing code without unit tests is like writing an article or essay without proofreading (this is not a dig at the author – I did not find any typos or errors – just using this as an analogy). Professionals write unit tests – hacks come up with excuses not to unit test.

    Unit testing not only proves that your code does what you think it’s going to do, but it documents your code, demonstrates how to use it, and makes it possible for you (or someone else) to make improvements to it without fear that they’ll break something else. It also forces you to write code that is much less brittle – if you can’t write a unit test for a class, then perhaps it’s because your class is poorly designed.

  3. Urs Enzler says:

    I agree with the advantages you write about. But I disagree with the statement that writing software with TDD takes more effort.
    Let me explain.

    Learning TDD and get good at it takes a lot of time. And here lies the problem. And probably this is the reason you think it’s extra effort, too ( wild guess 🙂 ).

    Once the team really can program in TDD style the speed is even higher. This is because much less bug hunting, less endless debug sessions, adapting to changed requirements much easier (especially if code is old), refactoring to get simpler code is feasible and so on.

    So there is no extra effort, but an investment in learning is needed – once – after that it’s less effort.

Comment