Basis path testing derives the number of ‘test cases’ that can be designed to exercise each & every statement in the program at the minimum once while testing is conducted to uncover all the possible errors of the program. Basis path testing is a method of testing the control structure of conventional software.
In this section, we will discuss the steps for conducting basis path testing. While studying the steps we will consider flow graph notation, identifying independent paths that helps in deriving the test cases.
Content: Basis Path Testing in Software Testing
- What is the Basis Path Testing?
- Flow Graph Notation
- Independent Program Path
- Deriving Test Cases
- Key Takeaways
What is the Basis Path Testing?
Basis path testing is one of the techniques of white-box testing which is used to test the control structure of any software. Basis path testing was first introduced by Tom McCabe.
Basis path testing technique helps the tester in deriving the number of test cases that can be conducted during testing, to exercise every statement in the program at the minimum once during the testing of the software to identify maximum errors in the program.
Now, to derive the test cases testers have to first draw the flow graph corresponding to source code or procedural design of the program, which will help in identifying the basis set (set of independent paths in the program) and then analyze the basis set to design the test cases that cover all the procedural statement of the program while testing.
Basis set could be identified without a flow graph, bu the flow graph provides useful notations to understand the control flow of the program. So, let us proceed with the flow graph.
Flow Graph Notation
The flow graph easily illustrates the control flow of the program. The flow graph is the graphical representation of procedural design (flow chart) of the program. For example, consider the flow chart below. We will map this flow chart to the flow graph.
The flow graph is represented with nodes and edges. The nodes of the flow graph represent one or more statements of the program. A single node can constitute a procedure statement along with the decision statement. The edges of the flow graph represent the control flow of the program.
The edge of the flow graph must always conclude to a node even though a node does not represent a procedural statement. A node that contains the conditional or decision-making statements is called the predicate node and it can be identified as two or more edges are emerging out of the predicate node.
For example, consider the image below where you can see the flow graph analogous to the flow chart above. You can see that statement 2 is a procedure statement and 3 is a decision-making statement and is mapped into a single node in the flow graph. You can even observe that node 9 and 10 does not represent any procedural statement still they are mapped to a node.
The areas enclosed inside the nodes are called regions. Now, in the flow graph below you can see area enclosed inside the edges connecting nodes 6, 7 8 and 9 is a region. When you identify regions in a flow graph the area at the extreme outside of the graph is also considered as a region.
Now, we will proceed to identify the independent paths from the above flow graph to determine the basis set.
An independent path is one that represents a path in the program that traces a new set of procedural statements or conditions. If we take it in the context of a flow graph, the independent path traces the edges in the flow graph that are not traversed before the path is defined.
As in the above flow graph, we can observe that the starting or the first node or procedural statement is node 1 and the termination of the flow graph is node 11. So, all the independent path that can be traced in the flow graph should start from 1 and end to 11:
Path 1: 1-11
Path 2: 1-2-3-4-5-10-1-11
Path 3: 1-2-3-6-8-9-10-1-11
Path 4: 1-2-3-6-7-9-10-1-11
Path 1, 2, 3 & 4 are the independent paths as each path introduces a new edge i.e. all the paths are unique. So, all these paths form a basis set for the above flow graph.
Now, if the test cases are designed to examine the basis set above it will be guaranteed that all the procedural statements in the program are evaluated and all the conditional statements are evaluated on both true and false sides.
Here, the question arises how can we identify how many independent paths can be traced in the flow graph. Well, this can be done by calculated cyclomatic complexity.
The value computed by cyclomatic complexity when considered in the context of basis path testing, the computed value helps in determining the number of independent paths that can be identified in the flow graph. And also provide minimum value up to which test cases can be designed to execute all the statements of the program.
The cyclomatic complexity V(G) can be calculated with the formulas below:
- V(G) = E – N + 2 // E is no. of edges in the flow graph, N is no. of nodes in the flow graph.
V(G) = 11 edges – 9 nodes + 2 = 4
- V(G) = P + 1 // P is no. of predicate node
V(G) = 3 predicate nodes + 1 = 4
- V(G)= no. of regions of a flow graph =4
So, for the above flow graph, there can be 4 independent paths and a minimum of 4 test cases can be designed to exercise all statements of the program.
Derive Test Cases
Basis path testing can be directly enforced on the source code or it can be applied to the procedural design to derive the test cases. Let us see step by step procedure of basis path testing:
Step 1: The first step is to draw a flow graph by reviewing the source code of the program or its procedural design.
Step 2: Reviewing the flow graph you have to compute cyclomatic complexity.
Step 3: The value computed by cyclomatic complexity provides the number up to which independent paths could be derived to determine the basis set.
Step 4: Reviewing the basis set testers design the test case that will exercise each statement in the program and every side of conditional statements in the program.
Advantages of Basis Path Testing
- This provides a systematic way of designing test cases.
- The cyclomatic complexity provides quantitative measures to derive the number of independent paths in the program. So, it becomes easy for testers to determine how many independent paths they have to look for.
- The test case designed with this technique covers all the statements of the program and ensures that each statement is executed at least once during testing.
- It uncovers all the possible errors of the program.
- Basis path testing is a white box testing technique that tests the control structure of the program.
- This testing technique derives the test cases that ensure the execution of each and every statement of the program.
- In this technique, the first flow graph is drawn reviewing the source code of the program or procedural design of the program.
- From the flow graph, the cyclomatic complexity is measured which enables testers to decide how many independent paths they have to look for.
- Reviewing the independent paths testers design test cases that ensure the execution of each and every statement of the program so that maximum errors are uncovered during testing.
So, this is all about the basis path testing. It is a technique of testing the control structure of the software to uncover the error. It is one of the techniques of white box testing.
Leave a Reply