Cucumber 我应该如何在场景大纲中命名我的步骤
我有一些specflow测试看起来像这样:Cucumber 我应该如何在场景大纲中命名我的步骤,cucumber,specflow,gherkin,Cucumber,Specflow,Gherkin,我有一些specflow测试看起来像这样: Scenario: Person is new and needs an email Given a person And the person does not exist in the repository When I run the new user batch job Then the person should be sent an email Scenario: Person is not new and needs an email
Scenario: Person is new and needs an email
Given a person
And the person does not exist in the repository
When I run the new user batch job
Then the person should be sent an email
Scenario: Person is not new and needs an email
Given a person
And the person does exist in the repository
When I run the new user batch job
Then the person should not be sent an email
除了2个场景之外,我有10个非常相似的场景,都有步骤类型,所以我想使用“场景大纲”。不幸的是,我真的很难想出一个可读的方法来重新编写我的步骤
目前,我想到了这个,但看起来很笨重:
Scenario: Email batch job is run
Given a person
And the person '<personDoes/NotExist>' exist in the repository
When I run the new user batch job
Then the person '<personShould/NotGetEmail>' be sent an email
Examples:
| !notes | personDoes/NotExist | personShould/NotGetEmail |
| Exists | does not | should |
| No Exist | does | should not |
场景:运行电子邮件批处理作业
给某人
并且存储库中存在人员“”
当我运行新用户批处理作业时
然后将向此人“”发送电子邮件
示例:
| !备注|个人姓名/备注存在|个人姓名/NotGetEmail|
|存在|不|应该存在|
|不存在|不存在|不应该存在|
我也考虑过这一点,虽然它更干净,但几乎没有传达出什么意思
Scenario: Email batch job is run
Given a person
And the person does exist in the repository (is '<personExist>')
When I run the new user batch job
Then the person should be sent an email (is '<sendEmail>')
Examples:
| !notes | personExist | sendEmail |
| Exists | false | true |
| No Exist | does | false |
场景:运行电子邮件批处理作业
给某人
并且该人员确实存在于存储库中(为“”)
当我运行新用户批处理作业时
然后应向此人发送一封电子邮件(为“”)
示例:
| !notes | personExist |发送电子邮件|
|存在|假|真|
|不存在|不存在|错误|
有没有人有更好的方法来参数化“做”、“不做”、“应该”、“不应该”、“有”、“没有”等概念?在这一点上,我正在考虑将所有内容作为一个不同的场景,因为它更具可读性。以下是我过去所做的:
Given these people exist in the external system
| Id | First Name | Last Name | Email |
| 1 | John | Galt | x |
| 2 | Howard | Roark | y |
And the following people exist in the account repository
| Id | External Id | First Name | Last Name |
| 45 | 1 | John | Galt |
When I run the new user batch job
Then the following people should exist in the account repository
| External Id | First Name | Last Name | Email |
| 1 | John | Galt | x |
| 2 | Howard | Roark | y |
And the following accounts should have been sent an email
| External Id | Email |
| 2 | y |
您可以使用SpecFlow中的table.CreateSet()和table.CreateSet()帮助器方法快速将这些表转换为假外部系统存储库和数据库中帐户表的数据
然后可以使用table.CompareToSet(accountRepository.GetAccounts()将“Then”子句中的表与数据库中的记录进行比较
最妙的是,您编写的所有步骤都可以在多种情况下重用。您所做的只是更改表中的数据,然后SpecFlow为您编写测试
希望能有所帮助!以下是我过去所做的:
Given these people exist in the external system
| Id | First Name | Last Name | Email |
| 1 | John | Galt | x |
| 2 | Howard | Roark | y |
And the following people exist in the account repository
| Id | External Id | First Name | Last Name |
| 45 | 1 | John | Galt |
When I run the new user batch job
Then the following people should exist in the account repository
| External Id | First Name | Last Name | Email |
| 1 | John | Galt | x |
| 2 | Howard | Roark | y |
And the following accounts should have been sent an email
| External Id | Email |
| 2 | y |
您可以使用SpecFlow中的table.CreateSet()和table.CreateSet()帮助器方法快速将这些表转换为假外部系统存储库和数据库中帐户表的数据
然后可以使用table.CompareToSet(accountRepository.GetAccounts()将“Then”子句中的表与数据库中的记录进行比较
最妙的是,您编写的所有步骤都可以在多种情况下重用。您所做的只是更改表中的数据,然后SpecFlow为您编写测试
希望有帮助!也许你应该把它们分成两种情况
Scenario Outline: User exists in the repository
Given a person
| Field | Value |
| First | <first> |
| Last | <last> |
And the person exists in the repository
When the user attempts to register
Then the person should be sent an email
Examples:
| first | last |
| Bob | Smith |
| Sarah | Jane |
场景大纲:存储库中存在用户
给某人
|字段|值|
|第一||
|最后||
并且该人员存在于存储库中
当用户尝试注册时
然后,应向此人发送电子邮件
示例:
|第一|最后|
|鲍勃·史密斯|
|莎拉·简|
然后是另一个相反的场景。这使场景的含义非常清楚。如果您的常用步骤措词一般,您可以重用它们。我还尝试从用户的方法中得出结论也许您应该将它们分为两个场景
Scenario Outline: User exists in the repository
Given a person
| Field | Value |
| First | <first> |
| Last | <last> |
And the person exists in the repository
When the user attempts to register
Then the person should be sent an email
Examples:
| first | last |
| Bob | Smith |
| Sarah | Jane |
场景大纲:存储库中存在用户
给某人
|字段|值|
|第一||
|最后||
并且该人员存在于存储库中
当用户尝试注册时
然后,应向此人发送电子邮件
示例:
|第一|最后|
|鲍勃·史密斯|
|莎拉·简|
然后是另一个相反的场景。这让场景的意思非常清楚。如果你的常用步骤措辞一般,你可以重用它们。我也尝试从用户的角度来看,你目前有10个测试……这似乎不多,除非测试本身有很多步骤——如果它们确实有很多麻烦的话步骤我们可能能够将测试推敲成适当的形状,这样表格和场景大纲就变得过于复杂了。您是否可以发布一个实际测试作为示例(最复杂的测试?),并强调在变体测试中发生变化的事情?你目前有10个测试…这似乎不多,除非测试本身有很多步骤-如果它们确实有很多繁琐的步骤,我们可能可以将测试推敲成适当的形状,以便表和场景大纲变得多余。你可以发布你的一个a吗以实际测试为例(最复杂的测试?),并强调在变体测试中发生的变化?