1
votes

I am new to BDD and Specflow and want to test the following scenarios.

Before I can Test I have to create some data in the database.

  • Application User
  • NursingHome where I need a reference to the Application User
  • Employee where I need a reference to the NursingHome

Then I add a job (from, to) to the employee. When I add a second job some tests should be executed.

Here is my first feature file attempt:

Feature: US01_AddEmploymentStatus
    It is not allowed that a employee has two jobs at the same time.
    A job can be closed.
    If a employee gets another job the old one is closed.


Background: 
    Given the following application user
        | FirstName   | LastName | UserName        | Password |
        | Application | User     | ApplicationUser | password |

    Given the following NursingHome
        | Name     | Street           | PostalCode | City       |
        | TestHome | Bahnhofstrasse 1 | 9020       | Klagenfurt |

    Given the following employee
        | FirstName | LastName   |
        | Max       | Mustermann |

Scenario: Employee changes his job.
    Given Max Mustermann has following job
        | From       | To   | State | QualificationId | NursingHomeId |
        | 01.01.2010 | null | 1     | 1               | ?             |
    And he get a new position
        | From       | To   | State | QualificationId | NursingHomeId |
        | 01.01.2014 | null | 1     | 2               | ?             |
    When I add the new postion
    Then the old one should be closed

How can I handle the references?

2

2 Answers

0
votes

There are two ways I can think of (assuming I've understood your domain correctly).

The first way is to save the 'old position' information in a variable (either in your steps class, or the ScenarioContext.Current or in a specific context object) and then in the step Then the old one should be closed you use that saved information to look up the state of the 'old position'

The second way (which I prefer) is to make your Then step much more explicit. So rewrite it like this:

Then the following positions should exist
| From       | To         | State | QualificationId | NursingHomeId |
| 01.01.2010 | 01.01.2014 | 1     | 1               | ?             |

I intially had steps which used things like you have in your original example but found this to be restrictive as soon as I wanted a scenario with more than 1 'old position'. Ie what if max has 2 part time jobs and then only one of them is closed when he takes on a third?

0
votes

In the Specflow Cook Book the Problem is described and solved (Chapter: Linking table rows). Now I have a glue how to add records to the database within the test, and use it.