Software Testing · Software Engineering

Data Flow Testing

Watch lectures

Data Flow Testing

Definition

Data Flow Testing is a white-box testing technique that focuses on the lifecycle of variables/data within the program — tracking where a variable is defined (assigned a value) and where it is subsequently used — to select test paths based on these define-use relationships, rather than just control flow.

Key Concepts

Definition (def)

A point in the code where a variable is assigned a value (e.g., x = 5;)

Use

A point in the code where a variable's value is read/referenced:

  • Computational use (c-use) — used in a computation/expression (e.g., y = x + 1;)
  • Predicate use (p-use) — used in a condition (e.g., if (x > 0))

Def-Use Chain (Data Flow Path)

The path from where a variable is defined to where it is used, without being redefined in between

Why Data Flow Testing Matters

Pure control-flow-based testing (like Path Testing) can miss bugs related to incorrect variable usage — e.g., using a variable before it's initialized, or a variable being redefined before its previous value is used (a "dead" assignment).

Common Data Flow Anomalies Detected

  1. Define without use — a variable is assigned but never used (dead code/wasted computation)
  2. Use without define — a variable is used before being initialized (a serious bug — undefined behavior)
  3. Define without use before redefine — a variable is assigned a value, but that value is overwritten before ever being used (likely a logic error)

Testing Strategy

  • Identify all def-use pairs for each variable in the code
  • Design test cases that execute the path from each definition to its corresponding use(s)
  • Ensures every meaningful data flow relationship is exercised at least once

Advantages

  • Catches a class of bugs (uninitialized variables, dead assignments) that pure control-flow testing misses
  • Particularly useful for programs with complex variable interactions

Disadvantages

  • More complex to design test cases for compared to simple path testing
  • Requires careful static analysis of the code to correctly identify all def-use pairs

Exam tip: Know the distinction between c-use (computational use, in an expression) and p-use (predicate use, in a condition), and be able to identify def-use pairs from a small code snippet.

Free AppAndroid App

Coursify Android App

Generate AI courses, take quick quizzes between classes, and master complex engineering concepts on the go.

← All Software Engineering modules