Using ColumnFixturesThis table style is probably the most generally useful in FitNesse. Many kinds of software features can be tested with ColumnFixture: any feature that can be expressed as rows of inputs and outputs.
ColumnFixture has the advantages of being easy to design and easy to understand. Below, we show a few more examples of uses for ColumnFixture. For starters, let's look at our test table for testing the division function of a calculator application:
The top row of the table provides the name of the ColumnFixtureCode that Fit will use to process the table. The second row specifies the inputs and outputs of the fixture; the column headings numerator and denominator specify columns of input values, and the quotient? heading specifies a column of expected return values. So if we divide 10 by 2, we expect to get back 5.
For a description of the fixture code for the Division example, see ColumnFixtureCode.
A Slightly More Complex Example: A Trivia GameLet's imagine that we are building a trivia game. The overall design of our trivia game is straightforward: players take turns rolling a single die, and move around a circular board. When they land on a square, they are asked a trivia question of some category. There are requirements for answering questions incorrectly, for winning, and so on.
For now let's imagine that we are addressing a specific first requirement or user story (call it what you like):
"You can add players to the game, and you can ask the game how many players are playing."Sounds pretty straightforward. Let's first set up a ClassPath that points to where our trivia game project is. Without the ClassPath, FitNesse would not be able to find our fixture code:
How about this for a test table for this requirement?
It says that if we add a player named Al to our game successfully, the total number of players should be 1, and if we then add a player named Bertha, our total number of players should be 2. If you click Test, you'll see that we have met this requirement. This is well and good, but it will be seldom that we can use a single table to do all the work to test a single requirement. We will typically need to use more than one table.
Say we have another requirement that goes like this:
"Once the game has started, players cannot be added or removed."
For this test, we'll ask the game to take a fake turn by specifying that the player whose turn it is "rolls" a 6. That should start the game. We'll check the result of that by checking to see which player it was who actually took the turn (we expect it to be Al), and whether indeed the game has started.
Now that the game has started, we'll try to add a new player to the game, and this should fail (we should get back false from addPlayer()). And we should still have only two players in the game:
Finally, we'll try to remove a player from the game, and this too should fail:
This shows how you can use a sequence of tables to verify a requirement by setting up and testing different states in your application code. This table sequence also illustrates one of the common AcceptanceTestPatterns: BuildOperateCheck.
For a description of the fixture code for the trivia Game example, see ColumnFixtureCode.
Another Example: an Inventory SystemLet's say you were writing an inventory system, and you wanted to test its ability to keep track of stocked items. You might write tables like this:
This test adds two stock items. The valid() method calls the parts of the system that cause a stock item to be added. Next, we might write a table that simulates some purchases that reduce the stock of an item.
Finally we'd write a table that checked to make sure that the inventory had been properly updated.
Learning MoreTo learn about the fixture code for the above examples, see ColumnFixtureCode.
Check out the other TestTableStyles to see which one suites your purposes best.