This is also a software testing type in which the source code of the software is checked line by line. The main objective is to check all the possible paths that the compiler may use to reach the output for the software.
Generally, path means the road or the way through the program control or data flows through a software. Basis path is based on the idea that a software has multiple entry and exit point. In this testing, this has to be checked that which entry and exit point is being followed by the software.
The aim of this testing is to check all the basis paths of the software.
To understand the software's basis path, we need to understand the Cyclomatic Complexity which is the metric to calculate all the independent paths inside the software.
This has to be understood that, basis path testing is totally a white box testing, as here the major concern is to test the source code and nothing is check in the outer part of the software or any part of the interface.
It is tested whether the data or the control flow follows all possible independent paths which are logically correct. This is a coverage based testing and tries to use the minimum number of test cases while executing the basis path.
Here, it is also checked that while following any of the independent paths, the software is able to reach a destination or a correct, consistent and atomic output.
Below with the help of a simple block diagram, we shall see how there can be more than one independent paths inside a software, which can be logically correct when the compiler scans the source code from either side.
As in the above diagram we have seen how the software is program control should reach the destination node which is NODE 6.
Here, it is clearly visible how there are different independent routes which can be chosen to reach the last or the destination node.
Here, we have seen that, the independent routes are: 1-2-3-4-5-6, 1-7-5-6 and 1-8-5-6 respectively.
The basic and most common steps for performing basis path testing is:
To understand Cyclomatic Complexity, we have to understand we should have an intuitive idea of software metric.
Software Metric is nothing but a quantity by which we can measure any property or attribute of a software in terms of time, cost, size, and effort.
Cyclomatic Complexity is a software metric for measuring the complexity of a program. This is used for calculation of independent path in a software or a program through which the program control may flow.
When we say independent path, it means that it is the path which has at least one edge which has not been traversed before any other paths.
Let us understand the notations first. Let us see the graph below.
Let us understand the flow graph notation:
The complexity of the code can be computed using the below formula:
Here, E is the number of edges.
N is the Number of Nodes.
Here, P is the number of predicate notes, which means that this node does not contain any condition.
Let us take an example of a program below:
a = 0; n=4; while (a<n-1) do b = a + 1; while (b<n) do if A[a]<A[b] then swap(A[a], A[b]); end do; a=a+1; end do;
The graph for the above program will be:
Now let us compute, V(G) = 9-7+2 = 4. (E-N+2)
Also, V(G) = 3+1. (P+1).
Let us now see what are the basis paths of the program. The independent paths are:
1-7, 1-2-6-1-7, 1-2-3-4-5-2-6-1-7, 1-2-3-4-5-2-6-1-7 and 1-2-3-5-2-6-1-7.
We shall not go deeper into the study of Cyclomatic Complexity. As we are concerned only about the basis path and all out independent paths are out basis paths.
There are different tools for computing the Cyclomatic Complexity of a graph. They are:
In Basis Path testing all the possible independent-paths through which the program or the software execution can flow and reach the output or the end. Different test cases are designed for executing different basis paths. Basis Path testing is purely a white box testing and also performs all the logical checks.
For finding the basis paths, we have to first compute the cyclomatic complexity and then the test cases are deployed. There are different tools to compute Basis Path Testing, they are: GMetrics, DevMetrics, NDepends and OCLint.