3.1. Calculating DiscountThe business rule for our first example follows.
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.
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]
Column labels in the header row serve two purposes.
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. |