/
Setup: Context definition (Developer)

Setup: Context definition (Developer)

Definition

The SetUpInterpreter 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.

When a setup table is executed, GreenPepper enter data in the system under development to create the desired state.

  • The first row of the table indicates the name of the interpreter and the name of the desired state.

  • The second row is called the header row and serves to identify the data to be inserted in the system under development.

  • Finally, the remaining rows captures the data to be inserted.

Coloring

GreenPepper will visually show the test result by coloring each testing cell:

GREEN

When the insertion has been executed successfully, GreenPepper add a green cell at the end of the data row with the word entered.

RED

If the insertion has failed because the values specified does not respect a business rule, GreenPepper add a red cell at the end of the row with the word not entered.

YELLOW

If the insertion has failed because a specified value generates an error, GreenPepper colors the cell of the data in error yellow and provides information about the error. 
If the system encounters an error not related to a specific data, GreenPepper add a yellow cell at the end of the data row and provides information about the error.

Writing fixtures for Setup tables

As we've seen in Setup Definition, 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.

Fixture to create bank customers

Consider the example of setup table described in Writing a Setup specification:

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.


For the third row GreenPepper carries out the following sequence of steps:

  1. It assigns the data 11111-11111 to numberchecking to typeFred to first nameFlintstone to last name and $250.00 to balance.
  2. It then calls the method enterRow() of the fixture AGroupOfCustomersFixture to open a bank account with the given datas.


Related content

Setup: Context definition
Setup: Context definition
More like this
Scenario: Scenario specification (Developer)
Scenario: Scenario specification (Developer)
More like this
Rule For: Rule Validation (Developer)
Rule For: Rule Validation (Developer)
More like this
List of, Set of, Superset of, Subset of: List Validation (Developer)
List of, Set of, Superset of, Subset of: List Validation (Developer)
More like this
Fixtures Conventions
Fixtures Conventions
More like this
Scenario: Scenario specification
Scenario: Scenario specification
More like this