Section 33.3. Setup


33.3. Setup

Before beginning to rewrite the fixtures, Emily and Neo reviewed the setup tables, as shown again in Figure 33.1.

Figure 33.1. Setup of Rentals for a Client


"Let's start by writing a minimal StartApplication class," suggested Neo, "and add code in small steps."

Listing 33.1. StartApplication.java (version 1)
 public class StartApplication extends DoFixture {     private RentEz rentEz; } 

"Good idea," replied Emily, "why don't you start."

Neo created a fresh version of the class StartApplication for testing through the domain layer, as shown in Listing 33.1.

He then ran the test, which failed at the start of the second table of Figure 33.1, as expected. "Each of the setup tables starts with setup," said Neo, "so again we'll need a separate fixture, as with the GUI-based fixtures."

The change he made to StartApplication is shown in Listing 33.2. A single object of GeneralSetUpFixture is created once and is used for all setup tables.

Two of the methods of the fixture class GeneralSetUpFixture written by Neo are shown in Listing 33.3. These methods in turn call into the API of RentEz.

The next step was for Emily and Neo to extend the API with these methods and get them working. They talked to Sarah, who added a Fit test to check that the setup had worked correctly. This gave them fast feedback on whether their new code was working correctly. It took several hours for Neo and Emily, between them, to get the new code working.

The test passed. Figure 33.2 shows the interaction of the fixtures with RentEz.

Figure 33.2. Setup


With this change, the tests were running at a better pace but still not fast enough. It was time to start untangling the presentation and domain layers so that testing could occur directly through the API.

Listing 33.2. StartApplication.java (version 2)
 public class StartApplication extends DoFixture {    private RentEz rentEz;    private GeneralSetUpFixture setUp;    public StartApplication() throws Exception {       rentEz = new RentEz();       setUp = new GeneralSetUpFixture(rentEz);    }    public Fixture setup() {        return setUp;    } } 

Listing 33.3. GeneralSetUpFixture.java
 public class GeneralSetUpFixture extends SetUpFixture {     private RentEz rentEz;     public GeneralSetUpFixture(RentEz phs) {         this.rentEz = phs;     }     public void staffNamePhone(String name, String phone) throws Exception {         rentEz.createStaffMember(admin(), name, phone);     }     public void clientNamePhone(String name, String phone) throws Exception {         rentEz.createClient(admin(), name, phone);     }     // ...     private StaffMember admin() throws MissingException {         return rentEz.getStaffMember("Admin");     } 



    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