FitNesse. UserGuide. FixtureGallery. FitLibraryFixtures.
SetUpFixture [add child]

Next page: CalculateFixture Parent page: FitLibrary Fixtures

SetUpFixture

SetUpFixture is an excellent replacement for ColumnFixture if you do not want to test anything, just to prepare the stage for other fixtures. For example, you can use SetUpFixture to insert rows into a database table or to create domain objects that will be used in later tests.

Table Format

The first row of a SetUpFixture table is the fixture class name. The second row lists property names for your object. All rows after that contain the property values. There are no output cells in a SetUpFixture table, all cells are used for inputs.


!|SetUpFixtureTest|
|player|post code|balance|
|John Smith|SW4 66Z|10.00|
|Michael Jordan|NE1 8AT|12.00|

Fixture class

The fixture class should extend fitlibrary.SetUpFixture and declare a single method. The method name should be equal to all the property names from the table joined together (you can use CamelCase capitalisation to separate words). The method should have an argument for each column in the table. The SetUpFixture table is executed by calling the method once for each data row in the table.

Java Source Code


package info.fitnesse.fixturegallery;

import info.fitnesse.fixturegallery.domain.Player;

import java.util.ArrayList;
import java.util.List;

import fitlibrary.SetUpFixture;

public class SetUpFixtureTest extends SetUpFixture{
public SetUpFixtureTest() {
Player.players.clear();
}
public void playerPostCodeBalance(String name, String postCode, double balance){
Player.addPlayer(name, postCode, balance) ;
}
}

.NET Source Code



namespace info.fitnesse.fixturegallery
{
public class SetUpFixtureTest : fitlibrary.SetUpFixture
{
public SetUpFixtureTest()
{
Player.players.Clear();
}
public void PlayerPostcodeBalance(string player, string postCode, decimal balance)
{
Player p = new Player();
p.Name = player;
p.PostCode = postCode;
p.Balance = balance;
Player.players.Add(p);
}
}
}

Python Source Code


from fitLib.SetUpFixture import SetUpFixture
from info.fitnesse.fixturegallery.domain.Player import Player

class SetUpFixtureTest(SetUpFixture):
_typeDict = {}

def __init__(self):
Player.players = []

# JAVA: void playerPostCodeBalance(String name, String postCode, double balance){
_typeDict["playerPostCodeBalance.types"] = [ None, "String", "String", "Float" ]
def playerPostCodeBalance(self, name, postCode, balance):
Player.addPlayer(name, postCode, balance)

Notes

The method name can be very long and typing it manually is a bit error prone. Instead of that, just write the table, run the test and it will fail for the first time.

Usage

Use the SetUpFixture to quickly initialise a list of domain objects, to prepare a database table or to execute a method several times with different arguments.

Do not use the SetUpFixture if the result of the operation or error verification is important. Use the ColumnFixture (see ColumnFixture) or the CalculateFixture instead.


Next page: CalculateFixture Parent page: FitLibrary Fixtures