Chair for Applied Software Engineering Prof. B. Brügge, Ph. D.
Software Engineering Exercise, SoSe 2009 Exercise 4 - (due May 20th)
1/2
Testing and Object Design Exercise
A control flow graph is a special form of a UML state diagram. It can be used to visualize the control flow in source code. Every instruction is a state and the states are associated by directed successor edges. Figure 1 shows an example of a control flow graph and its source code. For readability all states that do not have multiple successor states are collapsed into one state. E.g., in Figure 1 state B represents the statements a++ and b++.
Figure 1
Control flow graphs are useful also to visualize and reflect on the different coverage metrics of whitebox testing. If you assign names to the edges you can also define test cases on the control flow graph by specifying a sequence of edge names.
1) Control flow graph
Draw a control flow graph for the following source code:
While (a<3) { if (b<1) {
c++;
}
if (a>b) { b=a;
}
else if (c==3) { c++;
}
else { a++;
} }
2) Test cases on control flow graphs a) Design
Design a test case for the control for graph of 1) using the assigned numbers that has a statement coverage of 100%.
Chair for Applied Software Engineering Prof. B. Brügge, Ph. D.
Software Engineering Exercise, SoSe 2009 Exercise 4 - (due May 20th)
2/2 Hint: You can design a test case on a control flow graph by specifying a sequence of edges.
Statement coverage (a.k.a. line coverage): Percentage of statements in the source code that are executed when running the tests.
b) Implementation
What values do you need to assign to parameters a, b and c to implement the test case you designed?
3) Statement vs. branch coverage
Find an example, where branch coverage is different from statement coverage. Write the source code and define a test case in terms of sequence of instructions that conforms to your source code. Also draw a control flow graph for your code.
Branch coverage: Percentage of the branches in the control flow graph that are taken when running the tests.
4) Condition coverage vs. branch coverage
Find an example and define the control flow graph and a test case for it where condition coverage is lower than branch coverage.
Hint: To specify a test case for condition coverage you should not only define the sequence of edges but also the assignment of the atomic boolean expressions for branching.
(Simple) Condition coverage: Percentage of atomic boolean expressions that are assigned true and false when running the test cases.
5) Path coverage
Under which conditions is it possible to reach 100% path coverage for a program containing a for-loop?
Path coverage: Percentage of all possible statement sequences when executing the code
6) Calculating your test coverage
For your test case for the weak phrase validator determine your statement, branch and condition coverage.
Hand in your printed or hand-written solutions in the next exercise.