Using ColumnFixtures

This table style is probably the most generally useful in FitNesse. Many kinds of software features can be tested with Column Fixture: any feature that can be expressed as rows of inputs and outputs.

Column Fixture has the advantages of being easy to design and easy to understand. Below, we show a few more examples of uses for Column Fixture. For starters, let's look at our test table for testing the division function of a calculator application:

numerator denominator quotient?
10 2 5
12.6 3 4.2
100 4 33

The top row of the table provides the name of the Column Fixture Code 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 Column Fixture Code.

A Slightly More Complex Example: A Trivia Game

Let'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?

playerName addPlayer? countPlayers?
Al true 1
Bertha true 2

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.

roll player? gameHasStarted?
6 Al true

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:

playerName addPlayer? countPlayers?
Joe false 2

Finally, we'll try to remove a player from the game, and this too should fail:

playerName removePlayer? countPlayers?
Al false 2

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 Column Fixture Code.

Another Example: an Inventory System

Let'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:

partNumber quantity valid?
324 28 true
586 14 true

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.

partNumber quantity valid?
324 3 true
586 2 true

Finally we'd write a table that checked to make sure that the inventory had been properly updated.

partNumber quantity()
324 25
586 12

Learning More

To learn about the fixture code for the above examples, see Column Fixture Code. Check out the other Test Table Styles to see which one suites your purposes best.