Dashboard > GreenPepperOpen > ... > Writing the Fixtures > Fixtures to Setup the executable specification
  GreenPepperOpen Log In View a printable version of the current page.  
  Fixtures to Setup the executable specification
Added by Christian Lapointe, last edited by Francois Denommee on Mar 24, 2009  (view change)
Labels: 
(None)

Writing fixtures for Setup tables

As we've seen in Setup documentation, a table of rules is used to simplify the creation of a particular state for the system under development. Once the state is created, we can focus on the business process to test.

This page shows the fixture code that supports the examples introduced in the Writing a Setup Specification documentation.

Fixture to create bank customers

Consider the example of setup table described in Writing a Setup Interpreter Specification documentation:

Import
com.greenpepper.samples.application.bank
setup a group of customers
number type first name last name balance
11111-11111 checking Fred Flintstone $250.00
22222-22222 savings Fred Flintstone $10 000.00
44444-44444 savings Wilma Flintstone $10 000.00
55555-55555 checking Barney Rubble $999.54

The first cell of the first row indicates that a the SetupInterpreter will be used to interpret the table. The next cell says that the enterRow() method to use is in the fixture named AGroupOfCustomers. In Java, the name of the fixture is the name of a Java class. The enterRow() will be used to enter the data.

Instead of writing a method enterRow(), you can annotate the setup method with the annotation @EnterRow for Java ([EnterRow] for .Net). This way you can have a meaningful name for the setup method.

The second row, also known as the header row, designates the attribute columns of the data to be inserted. In our example, number, type, first name, last name and balance are the information to be created in the system under development.

The fixture code to support this example in Java is the class AGroupOfCustomersFixture shown below.

Show me the code

Code for the creation of a group of customers fixture
public class AGroupOfCustomersFixture 
{
	public AccountType type;
	public String number, firstName, lastName;
	public Money balance;
	public static Bank bank;
	
	public AGroupOfCustomersFixture()
	{
		bank=new Bank();
	}
	
	@EnterRow
	public void setupAccount()
	{
		if(AccountType.SAVINGS == type)
			bank.openSavingsAccount(number, new Owner(firstName, lastName)).deposit(balance);
		
		else if(AccountType.CHECKING == type)
			bank.openCheckingAccount(number, new Owner(firstName, lastName)).deposit(balance);
	}
}

How is the table processed?

When it runs this table,  GreenPepper reads the first row to select the interpreter and fixture. It then reads the second to know what are the attribute columns. Finally it starts creation of entries from the third row down to the end of the table.

Begin Info

For the third row  GreenPepper carries out the following sequence of steps:
It assigns the data 11111-11111 to number, checking to type, Fred to first name, Flintstone to last name and $250.00 to balance.
It then calls the method enterRow() of the fixture AGroupOfCustomersFixture to open a bank account with the given datas.

End Info

DEMONSTRATION LICENSE - This Confluence site is for demonstration purposes only. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.4.3 Build:#705 Mar 21, 2007) - Bug/feature request - Contact Administrators