Section 3.1. Calculating Discount


3.1. Calculating Discount

The business rule for our first example follows.

A 5 percent discount is provided whenever the total purchase is greater than $1,000.

We use examples in a table to help define the relationship between the amount and the discount for several cases. For example, when the amount is $1,100, the discount is $55. Figure 3.1 shows a simple set of tests for the part of a system that calculates discounts.

Figure 3.1. Fit Table for Testing Discount (with an Error)

CalculateDiscount

amount

discount()

0.00

0.00

100.00

0.00

999.00

0.00

1000.00

0.00

1010.00

50.50

1100.00

55.00

1200.00

60.00

2000.00

100.00


The fixture, CalculateDiscount, is named in the first row of the table. The fixture determines how the examples in the table are to be tested automatically against the system under test.

As this is a ColumnFixture table, the second row is a header row, which labels the given and calculated value columns. Here, the amount column holds the given values, and the discount() column holds the calculated results that are expected.[1]

[1] The label for a calculated result column has () after the name.

Column labels in the header row serve two purposes.

  1. They help us to understand the examples in the table.

  2. They are used when the examples are automatically tested by Fit.

The remaining eight test rows of the table are our test cases, which are checked one at a time. For the first test case, the given value under amount is 0, and so a calculated value of 0 under discount() is expected. The second test case is independent of the first; the given amount is 100, and so the calculated discount() is expected to be 0. And so on.

Fit runs the tests, one row at a time, against the system under test. Fit begins with the third row of the table, providing the given value of 0.00 to the application. Fit checks that the result calculated by the application, based on that amount, is 0.00, as expected.



    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