Section 28.7. Setup


28.7. Setup

As we saw in Section 10.4 on p. 76, a SetUpFixture table may be used for setting up the data at the start of a test. This example is shown again in the second table of Figure 28.6.

Figure 28.6. Discount: Various Tables


The fixture class Discounts, a DoFixture, is shown in Listing 28.8. The method setUp() is called for the action set up in the first row of the second table. This returns a fixture object, of class SetUpDiscounts, which is used to interpret the rest of the table.

The fixture class SetUpDiscounts is a SetUpFixture, as shown in Listing 28.9. SetUpFixture reads the labels in the second row of the table and combines them into the name of a method. The "%" in the fourth label is converted into "percent", as defined by extended camel casing (see the Note on the next page). In this case, the method is

 futureValueMaxBalanceMinPurchaseDiscountPercent() 

This method takes four arguments, corresponding to the four columns of the table.

For each subsequent row of the table, SetUpFixture calls that method with the values from the row. As usual, a TypeAdapter is used to convert the cell contents into suitable values for the method.

In general:

  • Before calling the method for the first time, the method startUp() is called. After all the rows have been processed, the method tearDown() is called. These methods can be overridden in a subclass of SetUpFixture to do pre- and postprocessing of the setup data.

  • An exception thrown when calling the method is reported in the table.

  • The setup method may be in the fixture itself or in the associated system under test, just as with DoFixture.



    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