Testing a sequence of actions on a System
Let's walk through a simple example of a test using a flow style interpreter.
First, we need to import the package containing the fixture code.
We need to specify the package in which our banking fixture is coded. Once the execution is started, GreenPepper searches the fixtures name in the package specified in the import tables.
| import |
| com.greenpepper.samples.application.bank |
We want to execute a sequence of actions on the bank fixture. We'll use the DoWithInterpreter for that.
Our first business rule says that a new account should have a balance of 0.00 dollars.
We will verify this rule with two actions. The first one opens an account and the second one checks its balance. The check keyword - in the first cell of the second row - indicates that we want to check the result of the action against the value specified in the last cell.
| open |
checking |
account |
12345-67890 |
under the name of |
Spongebob |
|
Squarepants |
| check |
that balance of account |
12345-67890 |
is |
$0.00 |
Savings account should follow the same rule. Let's verify that.
| open savings account |
54321-99999 |
under the name of |
Patrick |
|
Star |
| check |
that balance of account |
54321-99999 |
is |
0 |
Our next rule says that the bank should not take any fee when we deposit money in our account.
So if we deposit 100 dollars in one of the newly created accounts, we expect the balance to be exactly 100 dollars:
| deposit |
$100.00 |
in account |
12345-67890 |
| check |
that balance of account |
12345-67890 |
is |
$100.00 |
The following rule says that a customer should be able to withdraw funds if the balance of his account is sufficient.
| withdraw |
$50.00 |
from account |
12345-67890 |
| check |
that balance of account |
12345-67890 |
is |
$50.00 |
Nevertheless, checking accounts cannot go overdrawn. If we attempt to withdraw too much money, the bank should reject our request.
Let's try that:
| withdraw |
$75.00 |
from account |
12345-67890 |
| reject |
withdraw |
$75.00 |
from account |
12345-67890 |
| check |
that balance of account |
12345-67890 |
is |
$50.00 |
| accept |
withdraw |
$25.00 |
from account |
12345-67890 |
Once an account is frozen, we can deposit money in it, but not longer withdraw any money from it.
| freeze account |
12345-67890 |
| deposit |
$75.00 |
in account |
12345-67890 |
| reject |
withdraw |
$25.00 |
from account |
12345-67890 |
| check |
that balance of account |
12345-67890 |
is |
$100.00 |