Martin Kováčik

Software testing and code coverage

Notes I took:

http://www.onjava.com/pub/a/onjava/2004/06/16/ccunittest.html

Cyclomatic complexity can be explained in layman's terms as follows: every decision point in a method (i.e., an if, for, while, or case statement) is counted; additionally, one is added for the method's entry point, resulting in an integer-based measurement denoting a method's complexity.

For instance, the following uncomplicated method will yield a cyclomatic complexity value of 3.

public int getValue(int param1) {
   int value = 0;
   if (param1 == 0)  {
      value = 4;
   } else {
      value = 0;
   }
   return value;      
}

In the above method, there are two decision points: an if and an else. Remembering that a method's entry point automatically adds one, the final value equals 3.

Indeed, the example method is quite simple; however, one can imagine that if there were 10 additional decision points (yielding a cyclomatic complexity value of 13), the method may be perceived as complex. While one's opinion as to what construes code complexity is quite subjective, over the years the software industry has largely agreed that highly complex code can be difficult for engineers to understand and therefore harder to maintain. Moreover, highly complex code has a high probability of containing defects.


http://en.wikipedia.org/wiki/Code_coverage

Code coverage is a measure used in software testing. It describes the degree to which the source code of a program has been tested. It is a form of testing that looks at the code directly and as such comes under the heading of white box testing.


http://www.bullseye.com/coverage.html

This paper gives a complete description of code coverage analysis (test coverage analysis), a software testing technique.