在浏览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如果我想检查“服务咖啡”功能中的其他场景,该怎么办?例如,在一个场景中,支付了钱,但5分钟内没有按下按钮。
有几个场景有意义吗?或者我应该使用一个场景大纲吗?
谢谢!
发布于 2014-02-12 19:04:44
每个功能可以有多个场景,只要它们在逻辑上位于同一区域即可。如果你正在尝试解决一个不同的用例,我可能会建议你把它变成一个新特性。在您的情况下,看起来这两个场景在相同的功能下很适合。
Scenario Outline类似于NUnit中的TestCase,只有在相同的场景结构只需要不同的参数时才会使用它。
SpecFlow github站点上有很好的关于场景大纲here的文档。我将总结下面的代码示例。
假设一个功能中有两个场景:
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 |此大纲替换了您尝试参数化的方案定义。
发布于 2014-02-12 19:58:51
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场景的标准方法。所以答案是“是的,将与特定‘功能’(在这种情况下,何时以及如何提供咖啡)相关的场景放在一个功能文件中”。
如果您的咖啡机的功能文件扩展到有许多额外的场景,这些场景似乎描述了非常不同的功能,那么将它们移动到不同的文件中。
例如:
Feature: Coffee Machine Advertising video panel
Scenario: While my coffee is being served, I should be shown a 15 second advert.https://stackoverflow.com/questions/21725881
复制相似问题