31-Basis Path Testing-26-03-2024

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Module 5

White Box Testing – Basis Path Testing


White Box Testing
White Box Testing is a testing technique in which software’s internal structure, design, and
coding are tested to verify input-output flow and improve design, usability, and security.

It checks the logic of the program so that the results can be achieved

It is also known as glass box testing, structural testing, clear box testing, open box testing
and transparent box testing.

It tests internal coding and infrastructure of a software focus on checking of predefined


inputs against expected and desired outputs.

It is based on inner workings of an application and revolves around internal structure testing.
White Box Testing Coverage Criteria
Statement coverage – It ensures that each code statement is executed atleast once then
every bug will be notified.

Example:
while (a != b)
{
if(a>b)
a = a+b;
else
b = a-b;
}
printf(“a = “, a);
printf(“b = “, b); // No. of test cases required is 04
White Box Testing Coverage Criteria
Branch or Decision Coverage: Coverage of each code branch atleast once. Each branch
direction must be traversed atleast once.

Condition coverage: It states that each condition in a decision takes on all possible
outcomes atleast once. For example, consider the statement,
While ((a>b) && (a > c))

Test case 1: a>b, a>c


Test case 2: a>b, a<c

Compound Condition Coverage: For multiple conditions test each condition with multiple
paths and combination of the different path to reach that condition.
Why White Box Testing?
To ensure:

• That all independent paths within a module have been exercised at least once.
• All logical decisions verified on their true and false values.
• All loops executed at their boundaries and within their operational bounds internal data
structures validity.
Introduction to Basis Path Testing
Oldest structural testing technique

Based on the control structure of the program, testing is done.

Basis Path Testing is a White Box Testing method in which test cases are defined based on
flows or logical paths that can be taken through the program.

The objective of basis path testing is to define the number of independent paths, so the
number of test cases needed can be defined explicitly to maximize test coverage.

Basis path testing involves execution of all possible blocks in a program and achieves
maximum path coverage with the least number of test cases.
Steps for Basis Path Testing
The basic steps involved in basis path testing include

1. Draw a control flow graph or Decision to Decision (DD) graph (to determine different
program paths)
2. Calculate Cyclomatic complexity (metric to determine the number of independent
paths)
3. Find a basis set of paths / independent path
4. Generate test cases to exercise each path
Example 1: Design test cases for the below given program using Basis
Path Testing
Example 1: Design test cases for the below given program using Basis
Path Testing
Example 1: Design test cases for the below given program using Basis Path
Testing

(a) Draw the DD graph for the program


(b) Calculate the cyclomatic complexity
(c) List all independent paths
(d) Design test cases.
Example 1: Design test cases for the below given program using Basis
Path Testing
Step 1: Draw the control flow / DD graph
A Control Flow Graph (CFG) is the graphical representation
of control flow or computation during the execution of
programs or applications.
Example 1: Design test cases for the below given program using Basis
Path Testing
Step 2: Calculate Cyclomatic complexity

V(G) = e – n + 2p = 17 – 12 + 2*1 = 7

V(G) = no. of predicate node + 1 = 2 (Nodes B, C) + 1 = 7


Node C is a switch case, so finding the number of predicate node can be done using the
formula:
No. of predicate nodes = No. of links out of main node – 1
= 6 – 1 = 5 (Node C)
V(G) = No. of regions in the graph = 7

e – no. of edges; n – no. of nodes; p – no. of connected components in the graph


d – no. of decision nodes in the graph; Region – no. of independent path
Example 1: Design test cases for the below given program using Basis
Path Testing
Step 3: List down the independent paths

Path 1 : A - B - D – L
Path 2 : A – B – C –E – K – L
Path 3: A – B – C – F – K – L
Path 4: A – B – C – G – K - L
Path 5: A – B – C – H – K - L
Path 6: A – B – C – I – K - L
Path 7: A – B – C – J – K - L
Example 1: Design test cases for the below given program using Basis
Path Testing
Step 4: Design test cases
Example 2: Consider the code snippet below, for which we will
conduct basis path testing:
int num1 = 6;
int num2 = 9;
if(num2 == 0)
{
cout<<"num1/num2 is undefined"<<endl;
}
else
{
if(num1 > num2)
{
cout<<"num1 is greater"<<endl;
}
else
{
cout<<"num2 is greater"<<endl;
}
}
Advantages of Basis Path testing
The advantages of conducting basis path testing are:

1. Basis path testing reduces the number of redundant tests.


2. All program statements are executed and tested at least once.
3. It guarantees complete branch coverage.
References
1. Naresh Chauhan, Software Testing Principles and Practices, OXFORD University
Press, 2013.

You might also like