Section 5.2. Testing Lists Whose Order Is Important


5.2. Testing Lists Whose Order Is Important

Here's the business rule for discount groups, our second example.

The discount percentage that is provided depends on a customer's projected future value (high, medium, low), how much is owed, and the total amount of any one purchase. As the specifics of discount groups will change from time to time, their defining values will be stored in a configuration file.

This description is not easy to follow, a situation that often arises with requirements documents. We'll see that the following examples in this chapter and in the next will help clarify what's really required.

At this stage, we simply check that the current discount groups are stored in order, as expected, in the file. The fixture DiscountGroupOrderedList, a RowFixture, is named in the first row of Figure 5.7. The header row labels the five expected field values of each element in the list, from order to discount percent.

Figure 5.7. RowFixture Table That Tests Order Explicitly

DiscountGroupOrderedList

order

future value

max owing

min purchase

discount percent

1

low

0.00

0.00

0

2

low

0.00

2000.00

3

3

medium

500.00

600.00

3

4

medium

0.00

500.00

5

5

high

2000.00

2000.00

10


We have included a column order here to be explicit about the order of the elements in the file. (This value doesn't occur in the file, so it is added by the fixture.) Fit runs the table and compares the table rows with the elements of the list in the system under test. The report resulting from Figure 5.7 is shown in Figure 5.8.

Figure 5.8. Report


Questions & Answers

Q1:

What if two rows in the table are the same?

A1:

That's OK. There would need to be two matching rows in the actual list for the test to pass.

Q2:

Does the order of the columns in the table have to match the order of the values in the actual collection?

A2:

No. And it is not necessary to include all columns if they are not of interest in a particular test. This is illustrated by Figure 5.9, which passes.

Figure 5.9. Table That Tests Some Column Values

DiscountGroupArrayList

discount percent

future value

0

low

3

low

3

medium

5

medium

10

high


Programmers

The fixture code for the tests here is given in Section 23.2 on p. 197.


Note

For now, we have ignored how the discount groups are changed. We have simply tested that they are all as expected at a certain point in time. In Section 6.2 on p. 43, we show a sequence of tests that checks that additions to the discount groups are stored correctly.

Note that we're not testing that the discount groups are being handled correctly when discounts are calculated in the software; other tests are needed to do that. For example, either of the "medium" discount groups may apply, but which takes priority? We take this up in Section 6.2 on p. 43.




    Fit for Developing Software. Framework for Integrated Tests
    Fit for Developing Software: Framework for Integrated Tests
    ISBN: 0321269349
    EAN: 2147483647
    Year: 2005
    Pages: 331

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net