Basis path testing is a type of white-box testing that tests all possible independent paths in the control flow graph of a program.
Note:
- A path is the route of nodes in the control flow graph that a program takes from one point to another.
- An independent path is a path that adds at least one node in the already defined independent paths. In other words, the independent paths of a program are all unique.
To conduct basis path testing of a program, follow the steps below:
The advantages of conducting basis path testing are:
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; } }
The control flow graph of the code above will be as follows:
The cyclomatic complexity of the control flow graph above will be:
where,
E
= The number of edges in the control flow graph.N
= The number of nodes in the control flow graph.P
= The number of connected components in the control flow graph.The independent paths in the control flow graph are as follows:
The test cases to execute all paths above will be as follows:
Path | Input values |
Path 1: 1A-2B-3C-4D-5F-9 |
|
Path 2: 1A-2B-3C-4E-6G-7I-9 |
|
Path 3: 1A-2B-3C-4E-6H-8J-9 |
|
RELATED TAGS
CONTRIBUTOR
View all Courses