Section 16.2. Testing Calculations Instead


16.2. Testing Calculations Instead

Emily sketched out the test shown in Figure 16.3. As Seth pointed out, "This could be used for late returns as well."

Figure 16.3. Table for Early Returns

CalculateRefund

per hour

per day

per week

pay from

pay to

returned

refund()

0.05

0.45

2.00

2004/05/06 09:01

2004/05/06 12:01

2004/05/06 11:00

5.00


After adding some rows, Don suggested, "Why don't we simply write the hours, and so on, in directly? It's a pain working out the time differences from the dates." This led to the test shown in Figure 16.4. "The columns hours1, days1, and weeks1 give the time period that was paid for, and hours2, and so on, give the time before returning the rental items."

Figure 16.4. Revised Table

CalculateRefund

per hour

per day

per week

hours1

days1

weeks1

hours2

days2

weeks2

refund()

0.05

0.45

2.00

3

0

0

3

0

0

0.00

   

3

0

0

2

0

0

5.00

   

0

1

0

23

0

0

0.00

   

0

1

0

0

1

0

0.00


"That makes the table very wide. We could get rid of the left three columns by providing them to the table as a whole," suggested Emily. This resulted in the test shown in Figure 16.5.

Figure 16.5. Revised Table

CalculateRefund

0.05

0.45

2.00

hours1

days1

weeks1

hours2

days2

weeks2

refund()

3

0

0

3

0

0

0.00

3

0

0

2

0

0

5.00

0

1

0

23

0

0

0.00

0

1

0

0

1

0

0.00


Emily then suggested, "Let's split up the tables so we need to include only some columns; the rest we can assume to be 0. And let's be clear about what the rates are for in the first row. Let's use a DoFixture table to do that." This resulted in the tests shown in Figure 16.6.

Figure 16.6. Split Tables


Sarah then pointed out, "The refund calculation is one step removed from the underlying business rule: Which time period is fairer to use? To calculate the refund or the extra charge, we need to calculate the cost for the actual time period and subtract it from the original charge. So let's focus the test on the time periods." She then drew out some tables using this approach, as shown in Figure 16.7.

Figure 16.7. Fair Charge Tables




    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