Why I'm pushing for code coverage

Right now I'm make a push at work to increase the percentage code coverage by our unit tests. Let's just say that the numbers are very very low. But they are increasing. This morning as I was lying in bed I was wondering why I was fronting this initiative. I certainly have no qualms about making this push, but I'm trying to figure out all the reasons why. In the end I figured I would just put my thoughts down here.

Last winter I spent a bunch of time working as a maintenance/support programmer on this application and one thing became clear to me. When I went into the code I was never confident that the changes that I was making weren't breaking something larger than what I was working with. This was very nerve racking as I was regularly making hot fixes to the application and when fixing a bug the last thing you want to do is introduce a new problem. I know that writing tests will not prevent this from happening, but I would have like the comfort level that a well written test provides.

One of the most tried and true ways for developers to test their code is to try different scenarios in the belief that these manual tests will cover all possibilities. No matter how good a programmer or manual tester you are, there is no way that you can test and then state with certainty that you've covered all situations. For the lines that you didn't know that you didn't run, you have potential time bombs. Instead of risking these situations, I'd rather write tests and then strive to getting code coverage that nears 100%. The closer to 100% that I can get, the more likely I have eliminated all erroneous code.

The third reason that I'm making this push is non-coding. As your software grows and the complexity of its functionality increases you will begin to exert more and more pressure on your test team. While unit testing is not a replacement for real people testing, it can be used to relieve some pressure from them. If you know that you only touched some logic in a specific business function and that code is still passing all the tests, you probably can get away with a less vigorous manual test regime.

The last reason that I'm an advocate of having tests created is that they work as specifications embedded in the code base. You can look at a unit test(s) for a specific function and know exactly how that function is supposed to work. If you have no unit test to provide this information to you, you will have to search through the code in the function and hope it is correct, and that you read it correct, to determine how the code is functioning. Worse yet you will have to spend countless hours digging through design docs, change requests and other supporting documentation so that you can piece together the most recently signed off functionality for that part of the system. Having done this myself, you can trust me that it is not any fun.

Overall the spirit of testing is to provide a quick and consistently repeatable batch of code level tests that can aid in the verification of system functionality. Having tests provides another level of business knowledge to the developer, and it's in an environment that they are comfortable with. On top of all of this, unit tests can help, but don't guarantee, with increasing the quality of the code that your team turns out.

I'm the Igloo Coder and today I'm hot....hot and bothered....so quit pissing me off.

posted @ Saturday, July 22, 2006 4:23 PM

Print

Comments on this entry:

# re: Why I'm pushing for code coverage

Left by Lothan at 7/22/2006 5:08 PM
Gravatar
I have two primary (and I think realistic) reasons to push the code coverage level up a notch with unit tests. The first reason is to decrease the bug count and subsequent "hot fix" coding sessions to correct bugs found in production systems. Although these bugs are not usually catastrophic (thank goodness), they have been known to cause anomalies in subsequent systems and can be difficult to isolate and repair. Increasing code coverage of our unit tests help us isolate these types of bugs in development before we release to QA and therefore increases the overall reliability of the product in production and decreases our maintenance costs so we have more time to devote to customer needs. The second reason is to make future revisions to the software in a more stable and reliable manner. The primary source of concern with maintaining legacy systems is that we have limited methodologies to prove the systems work as intended or to prove that changes are consistent with old behavior. In a nutshell, how do you prove any given change to the software has not broken some feature or some code path if it is not covered by a unit test? Even if 70 percent of the code is under unit test, it leaves 30 percent or more of the code open to interpretation. The question then becomes whether correcting a flaw after a system has been in production for a while will break some other system that is dependent on that flaw. Thus, the reason for increasing code coverage is to identify and correct flaws in the system before these flaws become dependencies for other systems. I also believe that increasing total code coverage is aligned with our goals of implementing total quality management into our systems with continuous improvement processes.

# Intersting Finds: Rest of the leftovers from last week

Left by Jason Haley at 7/26/2006 7:39 PM
Gravatar

# Interesting Finds: Rest of the leftovers from last week

Left by Jason Haley at 7/26/2006 8:20 PM
Gravatar

Your comment:



 (will not be displayed)


 
 
 
Please add 2 and 4 and type the answer here:
 

Live Comment Preview: