Create test suites in flow mode

The second test in this chapter has two winners splitting the 4-out-of-6 prize. It follows the same basic script, with some different parameters. Let's make Arthur and Trisha guess four balls correctly (1,5,4,20). Arthur bets 80 dollars, Trisha bets 20, so the prize is split 4/1. The 4-out-of-6 prize is 10% of the payout pool (see Chapter 4, Writing basic tests), so Arthur should win 8 dollars, Trisha should win 2. If we use the same initial setup (giving each player 100 dollars up front), Arthur ends up with 100 (initial) - 80 (bet) + 8 (winnings)= 28 dollars. Trisha ends up with 100-20+2=82.

The initial setup is the same, so we don't want it in two places. Even though SetUp and TearDown (see Group related tests into test suites) are separate pages in FitNesse, they are included in the body of test pages before the test runs. If we start the flow mode in SetUp, it will affect the entire test. We can split a flow script into several components. Let's delete the first two tables from the previous test, and put them in a common setup:

SettlementTests.SetUp


1   !|Tristan.Test.Settlement.SettlementTest|
2   
3   |Accounts before the draw|
4   |player|balance|
5   |Arthur|100|
6   |Ford|100|
7   |Trisha|100|
8   |Marvin|100|

This now allows us to write the second test more easily: we specify just tickets, results and expected account balances.

SettlementTests.TwoWinnersFourBalls


1   !3 Arthur and Trisha guess 4 balls correctly (1,5,4,20). Arthur bet 80 dollars, Trisha bet 20, so the prize is split 4/1
2   
3   |Tickets in the Draw|
4   |player|numbers|value|
5   |Ford|2,11,22,33,39,18|50|
6   |Arthur|1,5,4,7,9,20|80|
7   |Trisha|10,1,20,5,4,11|20|
8   |Marvin|12,13,14,15,16,17|50|
9   
10  |Draw results are|1,5,4,20,38,37|
11  
12  |Accounts after the Draw|
13  |Player|Balance?|
14  |Arthur|28|
15  |Ford|50|
16  |Trisha|82|
17  |Marvin|50|