In data flow coverage, DU-paths are used to isolate a variable that is defined and used all over the code part.
In such a function scenario, how can I write test cases that cover all definitions of the variable x
?
Since it's only assigned a new value each time but not used anywhere in this function:
Function x (int y, int z) {
int x = 0;
M = y + z;
My_Array = [1,2,3];
if (0 < M < 10)
x = My_Array[1];
else if (10 < M < 20)
x = My_Array[2];
else
x = 0;
}
The way to use data flow analysis in testing is to
DU-path analysis assumes that all variables are Defined and then Used. When a variable isn't used before the end of the code, it's an error in the code and we correct it as above. DUK-path analysis considers "kills" (places where a variable is reassigned or exits the program), but it considers a kill without a use an error that needs to be corrected in the same way.
So, in your example, we eliminate all of the unused assignments and find that there is no code left, nothing to test, and the function can be inlined!