31-Basis Path Testing-26-03-2024
31-Basis Path Testing-26-03-2024
31-Basis Path Testing-26-03-2024
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 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))
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
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
V(G) = e – n + 2p = 17 – 12 + 2*1 = 7
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: