Section 21.2. Extending Credit


21.2. Extending Credit

The credit tests from Section 3.3 on p. 16 are shown again in Figure 21.3. Our fixture class is CalculateCredit, a ColumnFixture, as shown in Listing 21.2.

Figure 21.3. Fit Table for Testing Credit

CalculateCredit

months

reliable

balance

allow credit()

credit limit()

14

true

5000.00

true

1000.00

0

true

0.00

false

0.00

24

false

0.00

false

0.00

18

true

6000.00

false

0.00

12

true

5500.00

true

1000.00


There are three given columns, so the class has three corresponding instance variables, which are declared on lines 2-4 in Listing 21.2. The two calculated columns, allow credit() and credit limit(), correspond to the two methods allowCredit() and creditLimit() on lines 7 and 10 in Listing 21.2. The simple translation here is defined by camel casing; see the Note below. The two methods each make use of the values in the instance variables to call methods in the system under test, of class Credit.

Listing 21.2. CalculateCredit.java
 1 public class CalculateCredit extends fit.ColumnFixture { 2    public int months; 3    public boolean reliable; 4    public double balance; 5    private Credit credit = new Credit(); 6 7    public boolean allowCredit() { 8         return credit.allowsCredit(months,reliable,balance); 9    } 10   public double creditLimit() { 11        return credit.limit(months,reliable,balance); 12   } 13 } 

Note

Camel casing handles spaces separating words in a ColumnFixture or RowFixture table label, as well as in the names of fields in enter, press, and check actions in ActionFixture tables. These spaces have to be removed to get a valid Java identifier.

A sequence of space-separated words in the header is translated so that spaces are removed and the first letter of all words but the first is capitalized. For example, "allow credit" is translated into "allowCredit."

An extended form, extended camel casing, handles arbitrary characters in labels and actions in FitLibrary fixture tables, as discussed in Chapter 28.


The operation is much the same as in the previous example, except that

  • The first three columns are given. In running a test in a row, the values from each of these cells are assigned to each of the corresponding instance variables, working from left to right across the row.

  • There are two calculated columns. The corresponding methods are called in turn, from left to right across the row, using the instance variable values assigned by the givens.

Questions & Answers

Q1:

What if we want to test real numbers for equality?

A1:

Use class eg.ScientificDouble, available on the Fit Web site, at http://fit.c2.com. This class tests that the actual value is equal to the expected value to the precision of the expected value.

Q2:

What if an instance variable or method is missing?

A2:

The fixture code throws an exception if an instance variable or method doesn't exist or is not public, or if the calculated fixture method takes parameters.



    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