Selection and repetition control structures use the results of conditions to determine their actions.
The situation becomes more complicated as the complexity of the condition increases.
Fortunately, the sets of test data designed to check each pathway through the algorithm will also check the upper and lower values of each condition.
CASE STUDY In chapter 5, we developed a function for validating integers; the algorithm is reproduced below in Fig 6.4. Let us develop a set of test data that performs both path and decision coverage testing of this algorithm. Remember we are testing the algorithm for correctness, this does not ensure it meets the original design specifications nor does it ensure it operates efficiently. Later in this chapter, we examine methods for evaluating these issues. There are four inputs into this function; InputString, Min, Max and Default and a single output; ValidateInteger. Each test data set therefore requires four values together with a single expected output. The documentation detailing our test data sets should also include a reason for each set’s inclusion. The algorithm contains a single repetition and two binary selection statements. Three conditions in all, so there will be a maximum of eight (23) possible execution paths to test. Because of the repetition, it is possible for a single set of test data to check more than one path so it is likely that less than eight sets of test data will be needed to perform our path coverage tests.
Let us examine each of the eight paths and determine which should be possible and which should not be possible:
Possible test data to cover these paths could be:
As our existing test data covers the loop and first selection condition we need only consider the second selection condition in detail. This condition contains four identifiers - StringInteger, ValidInt, Min and Max. The first sub-condition, StringInteger is empty, requires a specific single value to evaluate to true. The second part of the condition is more involved; the value held in ValidInt must not lie within the range Min to Max, in other words, it must be outside this range. The most likely mathematical interpretation of this being ValidInt must be less than Min or greater than Max. We can use a decision tree to graphically depict this second selection condition (see Fig 6.5). The tree shows four possible methods of obtaining a result – three of these results being True and one being False. We need to design test data for each of these branches as well as data that matches the precise values within the condition.We already have test data that should result in StringInteger being empty (InputString set to Null or abc) and not empty (InputString set to 9a3). We also have test data that results in ValidInt being greater than Max We also require test data sets to check the precise values within the condition.
|
11 SDD > 8.2 Introduction to Software Development > 8.2.3 Testing and Evaluating Solutions > 1. Testing the Solution > 2. Test Data for Checking Algorithms and Code > 1. The Selection of Appropriate Test Data >
