Section 6.2. Discount Group Changes


6.2. Discount Group Changes

The business rule for determining the discount, based on the current discount groups, is as follows.

Given a future value, an amount owing, and a purchase price, look through the discount groups from the first to the last. For the first discount group that matches, use the discount percentage of that group to calculate the discount on the purchase.

Now a discount group matches if

  • The future value is the same as the future value of the group.

  • The amount owing is not greater than the maximum allowed for the group.

  • The purchase price is not less than the minimum price allowed for the group.

If no discount group matches, the discount is 0 percent.

We use four Fit test tables, as shown in Figure 6.4. All are ColumnFixture tables that together test this business rule.

  1. The first table configures the discount groups that are to be used in the subsequent tables of this test. The calculated column add() doesn't calculate anything; it is used simply to add the information in that row to the set of discount groups in the system under test.

  2. The second table tests the available discount only for low future value. The first cell of the second test row is an empty cell, which is low by default. As with all ColumnFixture tables, the value of an empty cell is assumed to be the same as the previous nonempty cell in that column of the table. In the report that's generated, as shown in Figure 6.5, the current value is shown in gray in the cell that in Figure 6.4 was empty.

  3. The third table tests the available discount only for medium future value. Like the previous table, it has empty cells in the first column.

  4. The fourth table tests the available discount only for high future value.

Figure 6.4. TestDiscountGroup


Figure 6.5. TestDiscountGroup Report


As with the example in the previous section, in order to make the tests easier to read, we have chosen to separate tables that could be combined. The tests for the three cases for future value are provided in separate tables.

Questions & Answers

Q1:

What happens if a cell in a ColumnFixture is empty but is the first one of the table?

A1:

It uses a default value, as defined in the fixture. For example, unless someone decides on a specific value by default, a number will be 0.

However, it's not a good idea to do this, because the initial value is hidden away; it's best to make it explicit in the first row of the table.

Q2:

What if we want the text to be empty, such as when the address is not known?

A2:

Write "blank" in the cell instead; this is treated as empty text instead of as "the same as above."

Programmers

The fixture code for the tests here is given in Section 24.2 on p. 208.


Tip

We used an add() column to add a set of elements to a list, as shown in the first table in Figure 6.4. It's a common pattern to have setup tables to do this. In Chapter 11 we'll see the use of another type of table for adding elements, one that supports this pattern and avoids the need for the last column.




    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