Q2Software Testing and Project Management
Question
(a) Explain the concept of White Box Testing techniques (Statement Coverage, Branch Coverage, Path Coverage) in detail. (b) Construct a control flow graph and calculate cyclomatic complexity.
Answer
A rigorous mathematical exploration of White Box Testing metrics, detailing Statement, Branch, and Path Coverage, culminating in the construction of a Control Flow Graph and the calculation of McCabe's Cyclomatic Complexity.
White Box Testing is an extreme, mathematically rigorous testing paradigm where the QA engineer physically dissects the internal source code architecture. The absolute objective is to prove that every single line of code, conditional branch, and physical loop is executed flawlessly. To mathematically quantify how thoroughly the code has been tested, engineers utilize strict Coverage Metrics.
1. Statement Coverage
The most primitive, bare-minimum mathematical metric.
- Definition: It mathematically guarantees that every single physical line of code (statement) in the architecture has been violently executed at least once during the test suite.
- Formula: (Number of Executed Statements / Total Statements) * 100
- Demerit: It is dangerously weak. It blindly executes the code but completely fails to test the mathematical logic of the FALSE conditions in IF statements.
2. Branch (Decision) Coverage
A significantly more aggressive mathematical metric.
- Definition: It strictly requires that every single boolean decision point in the architecture (every IF, WHILE, SWITCH) evaluates to both absolute TRUE and absolute FALSE at least once.
- Merit: If an IF statement has no ELSE block, Statement Coverage might ignore the invisible false path. Branch coverage violently forces the test suite to execute that invisible path, uncovering hidden architectural failures.
3. Path Coverage
The absolute most rigorous, mathematically exhausting coverage metric.
- Definition: It demands that every single possible independent execution path through the entire software architecture, from the start() node to the exit() node, is violently executed.
- Merit: It is mathematically perfect. However, in massive codebases with complex loops, the number of paths is astronomical, making 100% path coverage practically impossible without infinite time.
To calculate exactly how many independent paths exist (to satisfy Path Coverage), Thomas McCabe engineered a brilliant mathematical graph-theory technique called Cyclomatic Complexity.
The Control Flow Graph (CFG)
The source code is violently abstracted into a directed graph. Every single sequential block of code is a Node. Every logical jump or branch (like an IF statement) is an Edge connecting the nodes.
Consider this simple code:
``c
1. int x = read();
2. if (x > 10) {
3. print("Big");
4. }
5. print("Done");
``
- Node 1: Lines 1 & 2 (The condition)
- Node 2: Line 3 (The True branch)
- Node 3: Line 5 (The merge point)
- Edges: 1->2 (True), 1->3 (False), 2->3 (Merge).
Calculating Cyclomatic Complexity (V(G))
McCabe provided a strict mathematical formula to calculate the absolute number of independent paths in the CFG:
- = Total number of physical Edges in the graph.
- = Total number of physical Nodes in the graph.
- = Number of connected components (always 1 for a single program).
Using our CFG: - Edges () = 3 - Nodes () = 3 - .
The mathematical result is exactly 2. This absolutely proves to the QA engineer that they must write exactly 2 separate test cases to achieve 100% Path Coverage for this specific block of code.