IT Services in Metro Detroit Website Design Services in Metro Detroit Web Design Solutions in Metro Detroit Free Templates Knowledge Base Directory Contact Us

Effectively Improving Code Quality Using Unit Testing

By: Sameer Alibhai

What is Unit Testing? Unit testing, to put it simply, is to test the code in pieces. Each piece is independently tested from the others. It is commonly done as "white box testing", which you can think of as a transparent box that you can see into and based on what you see, that is what you test. Unit testing is often overlooked when it comes to software development. A lot of times software developers will skip this important step of unit testing (either automated, or even manual). By not checking if their code meets the basic business requirements, this can cost the company a lot of money and wasted effort. A bug caught earlier is much cheaper to fix than a bug caught later. Once you have to get QA (the Quality Assurance team) involved, you have already wasted money. Unit testing is an effective way of catching the bugs early in the process.

When you start to go to the next level of unit testing (automated unit testing), you will find even more benefits that come from unit testing. First of all, your tests can be automated and executed every night. This means that you now have a level of confidence in your code which you never had before. If you keep this up, you will know if your new code breaks the existing system in any way, since you are running these tests on a regular basis. At one of the companies which I worked, we slowly introduced unit tests into our application.

It started off as simple tests, and as time went by we added one for each significant bug that we found, to ensure that they would not repeat. This in turn strengthened the quality of our application and we were able to solve many problems much before the actual QA stage. This resulted in better code quality, and in turn the number of overall bugs that actually reached the customer was far less. Infact Microsoft is so convinced that they made unit testing a standard part of the new Visual Studio 2008! You can create your unit tests from right within the actual application.

For .NET, I recommend using NUnit or mbUnit in order to start with your unit testing. Begin with testing your core business objects, and slowly extend your reach. If you have a database, you can create database unit tests that are run nightly that check for existence of bad data such as customers being listed in the same region twice, and so on.

In conclusion, the benefits of unit testing far outweigh any potential minor increase in cost of development time. Start now, if you haven't already started!

Sameer Alibhai, administrator of a .NET C# programming blog, SharpDeveloper.NET, that gives you ways to add that little extra ZING to your code and succeed in the workplace.


Return to Index

(c) Web design by detro-it.com