0% found this document useful (0 votes)
106 views

White Box Testing Example: Consider The Below Simple Pseudocode

This document discusses different types of white box testing coverage: statement coverage, branch coverage, and path coverage. Statement coverage only tests each line of code once, which may not be sufficient. Branch coverage tests both the true and false conditions of if/else statements to achieve better coverage. Path coverage is needed for code with loops or combinations of decisions, requiring test cases for each path through the code graph. A pseudocode example demonstrates needing 4 test cases to achieve path coverage for code with two decision statements.

Uploaded by

RITIK KUMAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views

White Box Testing Example: Consider The Below Simple Pseudocode

This document discusses different types of white box testing coverage: statement coverage, branch coverage, and path coverage. Statement coverage only tests each line of code once, which may not be sufficient. Branch coverage tests both the true and false conditions of if/else statements to achieve better coverage. Path coverage is needed for code with loops or combinations of decisions, requiring test cases for each path through the code graph. A pseudocode example demonstrates needing 4 test cases to achieve path coverage for code with two decision statements.

Uploaded by

RITIK KUMAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

White Box Testing Example

Consider the below simple pseudocode:


INPUT A & B

C=A+B

IF C>100

PRINT “ITS DONE”

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.

So now the pseudocode becomes:


INPUT A & B

C=A+B

IF C>100

PRINT “ITS DONE”

ELSE

PRINT “ITS PENDING”

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.

TestCase_01: A=33, B=45


TestCase_02: A=25, B=30
With this, we can see that each and every line of the code is executed at least once.

Here are the Conclusions that are derived so far:


 Branch Coverage ensures more coverage than Statement coverage.
 Branch coverage is more powerful than Statement coverage.
 100% Branch coverage itself means 100% statement coverage.
 But 100 % statement coverage does not guarantee 100% branch coverage.
Now let’s move on to  Path Coverage:
As said earlier, Path coverage is used to test the complex code snippets, which basically involve loop
statements or combination of loops and decision statements.

Consider this pseudocode:


INPUT A & B

C=A+B

IF C>100

PRINT “ITS DONE”

END IF

IF A>50

PRINT “ITS PENDING”

END IF

Now to ensure maximum coverage, we would require 4 test cases.

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

PRINT “ITS DONE”

END IF

IF A>50

PRINT “ITS PENDING”

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:

Red Line – TestCase_01 = (A=50, B=60)

Blue Line = TestCase_02 = (A=55, B=40)

Orange Line = TestCase_03 = (A=40, B=65)

Green Line = TestCase_04 = (A=30, B=30)

You might also like