CH 03
CH 03
Black-box testing
Tests the item based on its interfaces and functional
requirements
Input values are varied over allowable ranges and
outputs compared to independently calculated values.
Input values outside of allowed ranges are also tested
to see if the unit responds according to specifications
Types of Testing (cont.)
White-box testing
Tests the unit with knowledge of its internal structure
Attempts to exercise as many paths through the unit as
possible
Statement coverage ensures that each statement is executed
at least once
Branch coverage ensures that every choice at each branch is
tested
Path coverage tests each path through a method
Example – testing all paths
8
The first two tests still pass with the new code
Case Study (cont.)
46
This fails, because our test for index < x.length comes too
late.
Case Study (cont.)
52
Examining our code, we note that we can fix this error and
make the code shorter at the same time by eliminating the
special case test location 0.
} public static int search(int[] x, int target) {
int index = 0;
while (index < x.length) {
if (x[index] == target)
return index; // target at index
index++;
}
return -1; // target not found
}
Running this will show you that *** does appear, but
does not trigger the loop exit. This suggests that
there is something wrong with the loop conditition.
The problem is that the condition word == “***” is
comparing addresses. The correct while condition is
while (word != null && !word.equals("***") && count < 10)
Using a Debugger
65