http://testerstories.com/2014/06/path-testing-the-coverage/
This week we turn to path coverage. Path coverage refers to test cases with linearly independent paths, in which a given program will execute at least once. A linearly independent path maps out the control flow of an application, which visually describes the execution path of a program in a sequence. Control flow graphs are numbered in sequence through all parts of a program. Each numbered segments serves as nodes in the execution path.
The article introduces the following coverages and their paths:
Node coverage has test cases that goes to every node in the graph.
Link coverage has test cases that goes to every link or line in the graph.
Loop coverage has tests that explores the interactions between sub-paths within a loop.
Node Coverage
1 2
1 3 4 7 6 8
1 3 4 5 6 8
Link Coverage
1 3 4 3 4 5 3 4 5 6 8
Loop Coverage
1 3 |4 3| 5 7 8
1 3 |4 3| 7 6 8
1 3 4 |5 3| 4 5 6 8
…
Through the different coverages, the example above shows the different paths that can be taken in the example program. What this example shows is that path testing maps out the control flow of an application and its execution paths to test out its coverages.
The coverage that I thought was interesting was statement coverage. Statement coverage is the lowest level testing coverage. It tests whether the flow of control has reached every executable statement at least once. The goal is to map out each executable code at least once.
The following example was given:
public class compute {
public static void main(String[] args) {
(1) float x = Float.valueOf(args[0]);
float y = Float.valueOf(args[1]);
(2) if (x != 0)
(3) y += 10;
(4) y = y / x;
(5) System.out.println(x + ” ” + y);
}
}
This maps out the path
3
1 -> 2 —>4 -> 5
Statement 2 divides into 2 conditionals, whether x is equal to 0, corresponding to condition 4, or not, corresponding to condition 3.
Statement coverage is defined by a percentage of number of statements executed over the total number of statements in the source code*100.
In this case the total number of statements in the source code is 5. If x = 0, then the number of statements executed is 4, providing 80% coverage. If x != 0, then this provides 100% coverage.
I first chose this article to learn more about path testing and coverage. I did not thoroughly understand the concept introduced in class until I went through this article. Though short, it provides a brief overview of the different coverages. However, the examples given in the article for the different types of coverages are inadequate. I particularly liked the examples provided for statement coverage. What I had learned is that statement coverage is simply a measure of how many execution paths are needed for 100% coverage. This demonstrates what path testing is all about, which is modeling the execution flow and testing its different paths for coverages.
From the blog CS@Worcester – Site Title by myxuanonline and used with permission of the author. All other rights reserved by the author.


