Section 38.2. SetUpFixture


38.2. SetUpFixture

Class SetUpFixture is an abstract subclass of CalculateFixture, as shown in Listing 38.2. To allow for actions before and after processing all the rows, the methods startUp() and tearDown() are provided. These methods can be overridden, for example, to make a database connection beforehand and shut it down once all the table rows have been added to the database.

As we see in Listing 38.2, SetUpFixture overrides doTable() of the superclass CalculateFixture to call the methods startUp() and tearDown() before and after processing the table. The doTable() code in CalculateFixture calls the method bind(), which is in turn overridden in SetUpFixture. If an exception occurs, details are provided in the report through a call to the Fixture method exception().

The bind() method in Listing 38.2 is responsible for creating a MethodTarget, which can be used to call a method in an object with arguments from a row, as we will see shortly. The bind() method does this by concatenating each label in the header row, separated by spaces, and then turning this into a valid Java method name through a call on a static method in the class ExtendedCamelCase. Then it calls the method findMethod() in the superclass, which returns a MethodTarget if it is able to find a matching method in the fixture object or in the associated application object, if any.

Class SetUpFixture overrides doRow() to process each row. If there is no valid binding, the row is marked as being ignored, through a call to the Fixture method ignore(). If there is a binding, it calls the invoke() method on the MethodTarget, which converts each cell into the type of value that's required for the corresponding argument of the method concerned and calls the method reflectively.



    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