Decision/Branch Testing and Coverage

Profile picture for user devraj

A more advance criterion for white box testing is branch coverage of the control flow graph. A decision is where there are two or more possible exist or outcome from statement. Decision statements are IF-Else, Control Loop and CASE statements. The result of the decision determines which statement is executed next.

Decision Coverage is stronger than statement coverage. Decision testing gives 50% of coverage if the condition is evaluated to true. Any stronger coverage measure may require more test cases to achieve 100% coverage. Decision coverage requires each decision to have had both a True and False outcome.

If the basis for a test is the control flow graph with its nodes and edges, then it is called a branch test or branch coverage.

Decision Coverage = (Number of decision outcomes exercised / Total number of decision outcomes) x 100%.

Consider an example:

1. Read X
2. Read Y
3. Z = 2X - Y
4. IF Z > 100 Then
5. Print Z larger than 100
6. END IF

Test 1_1: X=40, Y=30. Here value of Z = 50. Se have exercised false outcome of decision.
Test 1_2: X = 80, Y = 40. Here value of Z = 120. Now we have exercised true outcome of decision.

So, If we execute both test cases we have 100% test coverage. Some edges have been executed more than once. This seems to be redundant, but it cannot always be avoided.

It is reasonable to record which branches have been executed in which test case in order to find wrong execution flows. This helps to find faults, especially missing code in empty branches.

Branch coverage is also called C1-coverage. In contrast to statement coverage, branch coverage makes it possible to detect missing statements in empty branches. For object oriented system, statement coverage as well as branch coverage are inadequate because the control flow of the functions in the classes is usually short and not very complex.