BDD Specflow:处理数据库对象参考

时间:2014-10-14 07:16:24

标签: bdd specflow

我是BDD和Specflow的新手,想要测试以下场景。

在我可以测试之前,我必须在数据库中创建一些数据。

  • 申请用户
  • 护理之家,我需要参考应用程序用户
  • 我需要参考NursingHome的员工

然后我向员工添加一份工作(从,到)。当我添加第二个作业时,应该执行一些测试。

这是我的第一个功能文件尝试:

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

我如何处理参考文献?

2 个答案:

答案 0 :(得分:0)

我可以通过两种方式来思考(假设我已正确理解您的域名)。

第一种方法是保存旧位置'变量中的信息(在您的步骤类中,或ScenarioContext.Currentspecific context object中),然后在步骤Then the old one should be closed中使用保存的信息来查找&的状态#39;旧职位'

第二种方式(我更喜欢)是让你的Then步骤更明确。所以重写它是这样的:

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

我最初采用的步骤使用了原始示例中的内容,但发现只要我想要一个超过1个旧位置的场景,这就是限制性的。也就是说,如果max有2个兼职工作,然后只有其中一个在他接受第三个工作时关闭了什么?

答案 1 :(得分:0)

在Specflow Cook Book中描述并解决了问题(章节:链接表行)。现在我有一个粘合剂如何在测试中向数据库添加记录,并使用它。