Gregory M. KapfhammerAssociate Professor of Computer Sciencehttp://www.cs.allegheny.edu/~gkapfham/ |
Laboratory Seven, Group Two: Elizabeth Zehner and Daniel Fiedler
1. Types of Code Coverage
According to Code Coverage Analysis at http://www.bullseye.com/coverage.html#basic, there are seven kinds of Code Coverage: Statement ,Decision, Condition, Multiple Condition, Condition/Decision, Modified Condition/Decision, and Path.
Statement coverage "reports whether each executable statement is encountered." It can be applied to object (byte?) code and does not need source code. "However it is insensitive to certain control structures and some logical operators (&, ||). For example, Statement coverage cannot tell if a loop's terminating condition was met, only if the loop was executed." Statement coverage weighs computation more heavily than control. But the writer at bullseye.com argues that bad tests and bad code are usually more a result of bad control rather than bad computation.
Decision coverage "reports whether boolean expressions tested in control structures (such as the if-statement and while-statement) evaluated to both true and false. The entire boolean expression is considered one true-or-false predicate regardless of whether it contains logical-and or logical-or operators... This measure has the advantage of simplicity without the problems of statement coverage. A disadvantage is that this measure ignores branches within boolean expressions which occur due to short-circuit operators." So basically Decision Coverage says if an if statement or while loop was tested for both its true case and false case, treating statements linked by and/or as one big statement.
"Condition coverage reports the true or false outcome of each boolean sub-expression, separated by logical-and and logical-or if they occur. Condition coverage measures the sub-expressions independently of each other. This measure is similar to decision coverage but has better sensitivity to the control flow. However, full condition coverage does not guarantee full decision coverage." So basically Condition coverage is similar to decision coverage but tests each sub-statement of a big and/if statement individually.
Path coverage "reports whether each of the possible paths in each function have been followed. A path is a unique sequence of branches from the function entry to the exit. Since loops introduce an unbounded number of paths, this measure considers only a limited number of looping possibilities. Path coverage has the advantage of requiring very thorough testing. Path coverage has two severe disadvantages. The first is that the number of paths is exponential to the number of branches. For example, a function containing 10 if-statements has 1024 paths to test. Adding just one more if-statement doubles the count to 2048. The second disadvantage is that many paths are impossible to exercise due to relationships of data." Basically path coverage takes the branch statements from the assembly language (I think from the assembly language) and sees if you have a test covering all possible combinations of those branches - each combination is a path.
There are also less common measures: Function, Call, Linear Code Sequence and Jump (LCSAJ), Data Flow, Object Code Branch, Loop, Race, Relational Operator, Weak Mutation, and Table coverages.
From hansel.sourceforge.net - " Hansel aims at supporting a code coverage measure, that can always be achieved... The currently implemented code coverage class is decision coverage."
2. Purpose of Code Coverage
The most general reason to perform code coverage is to guarantee that all sections of code have tests cases to ensure their correctness. That is, if the test suite only covers 50% of the code, then it is irrelevant whether the test suite completely passes because the untested 50% of code has no guarantee of correctness. Code coverage can be used as an integral part of the test writing cycle because it shows places where increased coverage is needed. Then faults are found earlier in the game and this saves time and frustration.Dan Fiedler
Elizabeth Zehner
Link to this Page
- Laboratory Seven: Code Coverage Analysis with JUnit and Hansel last edited on 29 October 2002 at 6:52 pm by alden28.alleg.edu