通过SpecFlow文档,我试图弄清楚我的感知是否错误。我想为每个功能指定几个完全不同的场景。
例如:
Feature: Serve coffee
Coffee should not be served until paid for
Coffee should not be served until the button has been pressed
If there is no coffee left then money should be refunded
Scenario: Buy last coffee
Given there are 1 coffees left in the machine
And I have deposited 1$
When I press the coffee button
Then I should be served a coffee
如果我想检查" Serve coffee"中的其他情景怎么办?特征?例如,支付金钱但按钮没有按下5分钟的情况。
有多个场景或者我应该使用场景大纲是否有意义?
谢谢!
答案 0 :(得分:4)
每个功能的多个方案都可以,只要它们在逻辑上位于同一区域。如果您试图解决不同的用例,我可能会建议将其作为新功能。在您的情况下,看起来两个场景在同一个功能下可以正常使用。
场景大纲类似于NUnit中的TestCase
,如果相同的场景结构只需要采用不同的参数,则只能使用此方法。
在功能中给出两个场景:
Scenario: eat 5 out of 12
Given there are 12 cucumbers
When I eat 5 cucumbers
Then I should have 7 cucumbers
Scenario: eat 5 out of 20
Given there are 20 cucumbers
When I eat 5 cucumbers
Then I should have 15 cucumbers
您可以使用大纲参数化重复部分:
Scenario Outline: eating
Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers
Examples:
| start | eat | left |
| 12 | 5 | 7 |
| 20 | 5 | 15 |
此大纲取代了您尝试参数化的方案定义。
答案 1 :(得分:3)
Feature: Serve coffee
Coffee should not be served until paid for
Coffee should not be served until the button has been pressed
If there is no coffee left then money should be refunded
Scenario: Buy last coffee
Given there are 1 coffees left in the machine
And I have deposited 1$
When I press the coffee button
Then I should be served a coffee
Scenario: Store credit until a coffee is selected
Given I have deposited 1$
And I have left the machine for 5 minutes
When I press the coffee button
Then I should be served a coffee
您要问的是在要素文件中使用specflow场景的标准方法。所以答案是“是的,在一个特征文件中放置与特定'特征'相关的场景(在这种情况下,何时以及如何提供咖啡)”。
如果咖啡机的功能文件扩展为具有似乎描述完全不同功能的额外方案,则将它们移动到不同的文件中。
e.g。
Feature: Coffee Machine Advertising video panel
Scenario: While my coffee is being served, I should be shown a 15 second advert.