22.1. Buying Items Consider again the summing line items tests from Section 4.1 on p. 23, as shown in Figure 22.1. Figure 22.1. Fit Table for Testing Line Itemsfit.ActionFixture | start | BuyActions | check | total | 00.00 | enter | price | 12.00 | press | buy | check | total | 12.00 | enter | price | 100.00 | press | buy | check | total | 112.00 |
When it runs this table, Fit creates an object of the ActionFixture class and calls its method doTable(), as shown in Figure 22.2. This method interprets the actions, working down each row of the table in turn. Figure 22.2. Fit Runs the Table The start action in the second row of Figure 22.1 creates an object of the named class BuyActions, as shown in Figure 22.3. This is the actor; its class is shown in Listing 22.1. It starts the system under test, LineItems, as shown in Figure 22.4. Figure 22.3. ActionFixture starts the Actor Figure 22.4. The Actor Calls the System Under Test Listing 22.1. BuyActions.java public class BuyActions extends fit.Fixture { private LineItems lineItems = new LineItems(); private double currentPrice = 0.0; public void price(double currentPrice) { this.currentPrice = currentPrice; } public void buy() { lineItems.buyFor(currentPrice); } public double total() { return lineItems.totalIs(); } } The check (total) action in the third row calls the named method total() of the actor, which returns a double. This value matches the expected value, 0.00, in the third cell of the row, so it is marked with green. The enter (price) action in the fourth row calls the named method price() of the actor, passing to it the value 12.00 given in the third cell of the row. The value is used in the next action. The press (buy) action in the fifth row calls the named method buy() of the actor. This calls a method in the system under test, passing as a parameter the price that had just been entered. The check (total) action in the sixth row calls the named method total() of the actor. The returned value matches the expected value, 12.00, which is marked with green in the report, as shown in Figure 4.2 on p. 24. And so on. Questions & Answers Q1: | What if the price() method returned a value? | A1: | It doesn't matter whether a method corresponding to a press returns a value; the value is ignored by ActionFixture. | |