Chapter 23. Data-Flow Testing

In this chapter, we move on to white-box testing based on the data flows. Data-flow-based white-box testing is a good complement to control-flow-based white-box testing because there are certain types of bugs related to data handling that control-flow-based tests will not reveal.

In chapters 21 and 22, we looked at how to build white-box tests based on how the control flows through the code. However, there is more than just control flowing through programs. Most programs exist to deal with data. Programs accept data as input, process data, store data, retrieve data, and output data. In the course of this data being handled, it flows through the system. Perhaps we should figure out how to test these data flows?

You can analyze data flows using a technique called set-use pairs. To do this, you first identify each data item in the unit to be tested; that is, local variables, class members, and so on. For each data item, you identify pairs of lines in the unit where the item is first assigned a value, and then the item’s value is used. These are set-use pairs. Two lines are not a set-use pair if the data item will be set in some other line after being set in the first line and before being used in the second line. To test data flows, you need to cover all the set-use pairs.

Let’s look at an example. In Listing 23-1, you see our simple C program that accepts an integer input and prints the factorial of that input. The program uses three integer variables, which ...

Get Pragmatic Software Testing: Becoming an Effective and Efficient Test Professional now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.