White Box Testing Example: Consider The Below Simple Pseudocode
White Box Testing Example: Consider The Below Simple Pseudocode
C=A+B
IF C>100
For Statement Coverage – we would only need one test case to check all the lines of the code.
That means:
If I consider TestCase_01 to be (A=40 and B=70), then all the lines of code will be executed.
Now the question arises:
1. Is that sufficient?
2. What if I consider my Test case as A=33 and B=45?
Because Statement coverage will only cover the true side, for the pseudo code, only one test case would
NOT be sufficient to test it. As a tester, we have to consider the negative cases as well.
Hence for maximum coverage, we need to consider “Branch Coverage”, which will evaluate the “FALSE”
conditions.
In the real world, you may add appropriate statements when the condition fails.
C=A+B
IF C>100
ELSE
Since Statement coverage is not sufficient to test the entire pseudo code, we would require Branch
coverage to ensure maximum coverage.
So for Branch coverage, we would require two test cases to complete the testing of this pseudo code.
C=A+B
IF C>100
END IF
IF A>50
END IF
How? Simply – there are 2 decision statements, so for each decision statement, we would need two
branches to test. One for true and the other for the false condition. So for 2 decision statements, we would
require 2 test cases to test the true side and 2 test cases to test the false side, which makes a total of 4 test
cases.
To simplify these let's consider below flowchart of the pseudo code we have:
In order to have the full coverage, we would need following test cases:
INPUT A & B
C=A+B
IF C>100
END IF
IF A>50
END IF
TestCase_01: A=50, B=60
TestCase_02: A=55, B=40
TestCase_03: A=40, B=65
TestCase_04: A=30, B=30
So the path covered will be: