Control Flow Testing
Control Flow Testing is a white-box testing technique that analyzes the control flow graph of a program to design test cases. It focuses on executing various paths and decision points within the code to uncover logical errors.
First used·Mid-1970s
Definitions·1
Synonyms·3
Category·Software Testing
Also known as
Definitions
What it means.
- 01
Control Flow Testing in Software Engineering
In software engineering, Control Flow Testing is a white-box testing technique that focuses on the execution paths through a program. It uses the program's control structure, which is graphically represented as a Control Flow Graph (CFG), to systematically design test cases.
The goal is to verify the logical correctness of the program by examining its decision points and paths. The CFG is a directed graph where nodes represent basic blocks of code (a sequence of statements with one entry and one exit point), and edges represent the flow of control between these blocks, such as an
ifcondition leading to two different paths.Key Coverage Criteria Control Flow Testing encompasses several levels of coverage criteria, each with increasing rigor:
-
Statement Coverage: This is the most basic form. It aims to design test cases that execute every statement in the source code at least once. It helps in identifying dead code but can miss logical errors in decision points.
-
Branch Coverage (Decision Coverage): A stronger criterion that requires every possible outcome (e.g., true and false) of each decision point (like
if,while,switchstatements) to be tested. It ensures that all branches from a decision node are traversed. -
Path Coverage: This is the most comprehensive and demanding criterion. It aims to test every possible path from the entry point to the exit point of the program's control flow graph. For programs with loops, the number of paths can be infinite, making 100% path coverage impractical.
-
Basis Path Testing: A practical approach to path testing developed by Thomas McCabe. It uses the program's cyclomatic complexity to determine the number of linearly independent paths. Testing this basis set of paths guarantees that every statement and branch in the program is executed at least once.
Example Consider the following function:
function getGrade(score) { if (score >= 90) { return 'A'; // Path 1 } else { return 'B'; // Path 2 } }To achieve 100% branch coverage, two test cases are needed:
- A test case where
scoreis 90 or greater (e.g.,score = 95) to test thetruebranch. - A test case where
scoreis less than 90 (e.g.,score = 80) to test thefalsebranch.
-
Origin
Where it comes from.
Etymology
The term is a composite of "Control Flow" and "Testing." "Control Flow" refers to the order in which individual statements, instructions, or function calls of a program are executed. "Testing" is the process of evaluating a system. Thus, "Control Flow Testing" literally means testing based on the program's execution order.
Historical context
In the early days of computing, software testing was often an ad-hoc and intuitive process. With the rise of structured programming in the late 1960s and 1970s, there was a growing need for more systematic and rigorous testing methodologies.
This led to the development of white-box testing techniques that could analyze the internal logic of a program. The concept of representing program logic as a Control Flow Graph (CFG) became a powerful tool for this analysis.
A pivotal moment came in 1976 when Thomas J. McCabe, Sr. published his paper "A Complexity Measure." In it, he introduced the concept of cyclomatic complexity, a metric derived directly from a program's CFG. Cyclomatic complexity provides a mathematical basis for determining the number of linearly independent paths through a program. This gave birth to Basis Path Testing, a structured and practical form of Control Flow Testing.
Since then, Control Flow Testing and its associated coverage criteria (statement, branch, path) have become fundamental principles in software quality assurance, especially for mission-critical systems where logical correctness is paramount.
Usage
In context.
The QA team used Control Flow Testing to ensure that every logical path in the new payment processing module was validated.
To achieve 100% branch coverage, we designed our test cases using Path Testing, a form of Control Flow Testing.
By applying Structural Testing, the developers identified dead code that was never executed, improving the overall code quality.
The avionics software required rigorous Basis Path Testing to comply with safety standards.
FAQ
Common questions.
The primary artifact is the Control Flow Graph (CFG). A CFG is a graphical representation of all paths that might be traversed through a program during its execution. Nodes in the graph represent basic blocks of code, and the directed edges represent jumps in the control flow.
Taxonomy
Filed under.
Categories
Tags