Section 24.2. Discount Group Fixtures


24.2. Discount Group Fixtures

We now look at the fixtures underlying the tables in Section 6.2 on p. 43. Figure 24.4 shows the tables and objects. The example test is shown again in Figure 24.5.

Figure 24.4. Fit Runs the TestDiscountGroup Tables


Figure 24.5. TestDiscountGroup


Listing 24.4 shows the fixture code for the first table of Figure 24.5. The code makes use of a static variable APP so that the fixture objects for each of the tables can access the same system under test. Whenever the system under test is needed in the fixture, a call is made to the static method getApp(), which returns the DiscountApplication object, which is created once, when it is first needed.

The method add() of class DiscountGroupsEntry, as shown in Listing 24.4, is called in turn for each row of the first table. The code simply simply calls the addDiscountGroup() method of the system under test and returns TRue to show that the addition was successful.

Listing 24.5 shows the fixture code for the other tables. This fixture class accesses the system under test through the static variable of class SetDiscountGroups.

Questions & Answers

Q1:

Could DiscountGroupsEntry and CalculateDiscounts be combined?

A1:

Yes, into a single class in this case, given that they're both ColumnFixtures. It's still necessary to use a static variable, because a fixture object is created for each table.

Listing 24.4. DiscountGroupsEntry.java
 public class DiscountGroupsEntry extends fit.ColumnFixture {    public double maxBalance, minPurchase;    public String futureValue, description = "";    public double discountPercent;    private static DiscountApplication APP;    public boolean add() {       getApp().addDiscountGroup(futureValue,maxBalance,                          minPurchase,discountPercent);       return true;    }    public static DiscountApplication getApp() {       if (APP == null)          APP = new DiscountApplication();       return APP;    } } 

Listing 24.5. CalculateDiscounts.java
 public class CalculateDiscounts extends fit.ColumnFixture {    public String futureValue;    public double owing, purchase;    public double discount() {       return DiscountGroupsEntry.getApp().discount(                   futureValue,owing,purchase);    } } 



    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