Explanation: Statement coverage and decision coverage are both less than 100%. Statement coverage is a criterion that requires every executable statement in the source code to be executed at least once by a test suite1. Decision coverage is a criterion that requires every decision (or branch) in the source code to take both true and false outcomes at least once by a test suite1. The flow graph below shows the logic of a program for which 100% statement coverage and 100% decision coverage is required on exit from component testing. The flow graph has 9 nodes (A, B, C, D, E, F, G, H, I) and 10 edges (1, 2, 3, 4, 5, 6, 7, 8, 9, 10). The edges represent executable statements and the nodes represent decisions or branches.
!flow graph
The following test cases have been run:
- Test Case 1 covering path A-B-C-D-E-F-G-H-I
- Test Case 2 covering path A-B-C-D-E-F-G-H
- Test Case 3 covering path A-B-C-D-E-F
- Test case 4 covering path A-B-C-D-E
To calculate the statement coverage and decision coverage achieved by these test cases, we can use the following formulas:
- Statement coverage = (Number of statements executed / Total number of statements) x 100%
- Decision coverage = (Number of decisions exercised / Total number of decisions) x 100%
In this case, the number of statements executed by the test cases is 8 (edges 1, 2, 3, 4, 5, 6, 7, and 9). The total number of statements in the flow graph is 10 (edges 1 to 10). Therefore, the statement coverage achieved by the test cases is:
- Statement coverage = (8 / 10) x 100% = 80%
The number of decisions exercised by the test cases is also 8 (nodes A, B, C, D, E, F, G, and H). The total number of decisions in the flow graph is also 10 (nodes A to J). Therefore, the decision coverage achieved by the test cases is:
- Decision coverage = (8 / 10) x 100% = 80%
Therefore, statement coverage and decision coverage are both less than 100%. To achieve 100% statement coverage and decision coverage, two more test cases are needed to cover edges 8 and 10 and nodes I and J.