TL;DR
Let’s provide an example of structural code coverages. The post is aligned with the Black Box Software Testing Foundations course (BBST) designed by Rebecca Fiedler, Cem Kaner, and James Bach.
We will provide examples for the following structures:
- statement coverage
- branch coverage
- multi-condition coverage
- loop coverage
Here is a simple program in pseudocode:
INPUT A FROM KEYBOARD INPUT B FROM KEYBOARD INPUT N FROM KEYBOARD IF (A < 3) PRINT A IF (B == "ZABOK") PRINT B WHILE (0 < N < 10) {N = N + 1}
Statement 100% coverage
To achieve statement 100% code coverage, we need to run one test:
Enter 2 for A, enter "ZABOK" for B, enter 1 for N
Branch 100% coverage
We need two test cases:
Enter 2 for A, enter "ZABOK" for B Enter 3 for A and enter "AMSTERDAM" for B
Note that branch coverage includes the test for statement coverage
Multi-condition coverage
All combinations of logical expressions. We need a table for that:
We have 36 tests.
Loop code coverage
We have nine tests:
Enter 2 for, enter "ZABOK" for B, enter for N 1 Enter 2 for, enter "ZABOK" for B, enter for N 2 Enter 2 for, enter "ZABOK" for B, enter for N 3 Enter 2 for, enter "ZABOK" for B, enter for N 4 Enter 2 for, enter "ZABOK" for B, enter for N 5 Enter 2 for, enter "ZABOK" for B, enter for N 6 Enter 2 for, enter "ZABOK" for B, enter for N 7 Enter 2 for, enter "ZABOK" for B, enter for N 8 Enter 2 for, enter "ZABOK" for B, enter for N 9