Chair for Applied Software Engineering Prof. B. Brügge, Ph. D.
Software Engineering Exercise, SS2009 Solution 4
1/1
Whitebox Testing Exercise
1) Coverage Metrics
• Statement coverage
• Branch coverage
• Condition coverage o Single
o Multiple o Minimum
• Path coverage
2) Control flow graph
Figure one shows a valid control flow graph for the given source code. Note that some states have been collapsed.
Figure 1: Control flow graph for exercise 1
3) Test cases on control flow graphs a) Design
You can design a test case on a control flow graph by specifying a sequence of edges.
A sequence that will execute every statement is:
1, 2, 3, 5, 6, 7, 13, 2, 4, 8, 9, 10, 14, 2, 4, 8, 11, 12, 13, 14
Chair for Applied Software Engineering Prof. B. Brügge, Ph. D.
Software Engineering Exercise, SS2009 Solution 4
2/2 b)
Implementation
The test case from a) can be implemented by using he following parameter assignments to run the code to be tested:
a=2 b=0 c=2
4) Statement vs. branch coverage
Test case: 1, 2
Statement coverage: 100%
Branch coverage: 50%
Additional test case to reach 100% branch coverage: 3
5) Condition coverage vs. branch coverage
Test cases:
• 1, 2 with a>4 and b>4
• 3 with a<=4 and b>4 Branch coverage: 100%
Condition coverage: 75% (b is never false)
Additional test case to reach 100% condition coverage: 3 with a<=4 and b<=4
6) Path coverage vs. branch coverage
If the loop is always of a fixed length, one can reach 100% path coverage. Otherwise one cannot know how many times the loop will possible run and therefore one cannot design test cases for every possible path.