COMP 4004 Lecture Notes - Lecture 4: Code Coverage, Switch Statement, Unit Testing
9 – Control Flow Coverage
• Method coverage
• Statement coverage
• Branch coverage (also called decision coverage)
o Minimum coverage specified by the IEEE unit test standard
• Multiple Condition coverage
o Covers combinations of condition in decisions
• Path coverage
o 100% path coverage impossible in practice (loops)
• Flow graph
o The flow graph on the right is determined from the code on the left:
• Statement Coverage
o Criterion: All statements must be covered during test execution
o This is the weakest form of coverage
▪ Some branches may be missed
o Find paths that cover all statements
o Choose input data that will result in the selected paths
o Ex. The following path is sufficient for statement coverage:
1 – 3 – 4 – 5 – 7
▪ Possible input: a = 2, b = 0, x = 4
• Branch Coverage
o Criterion: At any branch point, each branch must be covered during test execution
▪ The true and false branch of a 2-way if statement.
▪ Each case in a switch statement.
o Find paths that cover all branches
o Choose input data that will result in the selected paths
o Branch coverage necessarily includes statement coverage