首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Specflow:为每个功能指定多个方案

Specflow:为每个功能指定多个方案
EN

Stack Overflow用户
提问于 2014-02-12 18:55:29
回答 2查看 11.6K关注 0票数 6

在浏览SpecFlow文档时,我试图找出我的看法是否错误。我想为每个功能指定几个完全不同的场景。

例如:

代码语言:javascript
复制
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分钟内没有按下按钮。

有几个场景有意义吗?或者我应该使用一个场景大纲吗?

谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-02-12 19:04:44

每个功能可以有多个场景,只要它们在逻辑上位于同一区域即可。如果你正在尝试解决一个不同的用例,我可能会建议你把它变成一个新特性。在您的情况下,看起来这两个场景在相同的功能下很适合。

Scenario Outline类似于NUnit中的TestCase,只有在相同的场景结构只需要不同的参数时才会使用它。

SpecFlow github站点上有很好的关于场景大纲here的文档。我将总结下面的代码示例。

假设一个功能中有两个场景:

代码语言:javascript
复制
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

可以使用轮廓参数化重复零件:

代码语言:javascript
复制
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  |

此大纲替换了您尝试参数化的方案定义。

票数 6
EN

Stack Overflow用户

发布于 2014-02-12 19:58:51

代码语言:javascript
复制
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场景的标准方法。所以答案是“是的,将与特定‘功能’(在这种情况下,何时以及如何提供咖啡)相关的场景放在一个功能文件中”。

如果您的咖啡机的功能文件扩展到有许多额外的场景,这些场景似乎描述了非常不同的功能,那么将它们移动到不同的文件中。

例如:

代码语言:javascript
复制
Feature: Coffee Machine Advertising video panel

Scenario: While my coffee is being served, I should be shown a 15 second advert.
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21725881

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档