40.2. Generate a Simple SequenceAs with development generally, it makes sense to go step by step. A sensible first step is to generate a simple test and see that it works. We can then extend our test generator as we get clearer about what it needs to do. We may find that a simple approach works fine and there is no point in making it more sophisticated. Or, after some use, we may find ways of improving it that weren't obvious initially. After all, it's just as hard for us to see the future clearly as it is for customers. To generate a sequence, we will need to have a representation of the clients and rental items in our simulation. Then we can randomly pick a client and some rental items to be rented and later returned. In this first step, we simply generate a single test that rents and then immediately returns each RentalItem. Listing 40.1 shows the first part of the code for class Generate1, a subclass of CustomRunner. Some initial setup data for clients and rental items is created in static arrays, and this is used in makeSetUp(). The constructor for Generate1 in Listing 40.1 creates the tables and runs the CustomRunner on them to produce a Fit report with title RPS. (See Chapter 39 for an introduction to the use of CustomRunner.) The remainder of class Generate1 is shown in Listing 40.2. The makeTables() method randomly chooses a RentalItemModel that has some items available for rental. The method generates one table to rent all those items and a second table to immediately return them. The makeCheck() method in Listing 40.2 generates the final table, which checks that no RentalItems are outstanding. This could be improved by also checking that the rentals are back to their original numbers. (See the exercises at the end of the chapter.) The method makeSetUp() in Listing 40.1 generates the Fit tables for initializing the setup data in the system under test. This uses the method setUpRow() in both ClientModel and RentalItemModel to return the relevant data to be inserted in the row of the setup table. Class ClientModel is shown in Listing 40.3, and class RentalItemModel is shown in Listing 40.4. Listing 40.1. Generate1.java (part 1)
Listing 40.2. Generate1.java (part 2)
Listing 40.3. ClientModel.java
Listing 40.4. RentalItemModel.java (version 1)
|
Saturday, November 7, 2009
Section 40.2. Generate a Simple Sequence
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment