【问题标题】:Multi dimensional Scenario Outlines in SpecflowSpecflow 中的多维场景大纲
【发布时间】:2013-10-31 14:49:36
【问题描述】:

我正在创建一个类似于以下的场景大纲(它是一个简化版本,但很好地表明了我的问题):

Given I have a valid operator such as 'MyOperatorName'
    When I provide a valid phone number for the operator 
    And I provide an '<amount>' that is of the following '<type>'
    And I send a request 
    Then the following validation message will be displayed: 'The Format of Amount is not valid'
    And the following Status Code will be received: 'AmountFormatIsInvalid'

Examples:
    | type      | description                     | amount |
    | Negative  | An amount that is negative      | -1.0   |
    | Zero      | An amount that is equal to zero |  0     |
    | ......... | ..........                      | ....   |

示例表提供了我需要的测试数据,但我会添加另一个示例表,其中仅包含操作员的名称(而不是 MyOperatorName),以便为不同的操作员复制测试

Examples: 
   | operator  |
   | op_numb_1 |
   | op_numb_2 |
   | op_numb_3 |

为了避免重复三遍相同的场景大纲;我知道这是不可能的,但我想知道避免在功能内部使用三个不同的场景大纲的最佳方法是什么,除了操作员名称外,它们几乎相同。 我知道我可以重复使用相同的步骤定义,但我正在尝试了解是否有最佳实践来防止过于相似的场景使功能混乱。

【问题讨论】:

    标签: cucumber bdd specflow gherkin


    【解决方案1】:

    很高兴您知道这是不可能的... 那么有哪些选择呢? 好像有5个:

    a:用每个选项(叉积)制作一个表格

    Examples:
    
     | type      | description                     | amount | operator  |
     | Negative  | An amount that is negative      | -1.0   | op_numb_1 |
     | Zero      | An amount that is equal to zero |  0     | op_numb_1 |
     | Negative  | An amount that is negative      | -1.0   | op_numb_2 |
     | Zero      | An amount that is equal to zero |  0     | op_numb_2 |
     | ......... | ..........                      | ....   | ...       | 
    

    b.为每个运算符重复该场景,并使用输入行表 - 但你说你不想这样做。

    c。使用运算符表对每个输入行重复该场景 - 我喜欢这个选项,因为每个 rule 都是一个单独的测试。如果您真的非常想确保您的“操作员”策略的每个不同实现在相同的验证场景中通过和失败,那么为什么不将每个验证场景编写为单个场景大纲:例如

    Scenario Outline: Operators should fail on Negative inputs
    Given I have a valid operator such as 'MyOperatorName'
    When I provide a valid phone number for the operator 
    And I send a request with the amount "-1.0"
    Then the following validation message will be displayed: 'The Format of Amount is not valid'
    And the following Status Code will be received: 'AmountFormatIsInvalid'
    
    Scenario Outline: Operators should fail on Zero inputs
    ...etc...
    

    d。重新考虑如何使用 Specflow - 如果您只需要 KEY 示例来说明您的功能(如 Gojko Adzic 的 Specification by Example 所述),那么您通过检查每个组合来过度使用它。但是,如果您使用 specflow 来自动化您的全套集成测试,那么您的场景可能是合适的......但您可能需要考虑 e。

    e。基于您的“操作员”验证逻辑仅在一个地方应用的想法编写集成/单元测试。如果每个运算符的验证都相同,为什么不测试一次,然后让所有运算符继承或包含在它们的组合中相同的验证器类?

    【讨论】:

    • 公平地说,When I provide a valid phone number for the operator 在选项 c 中有点多余。 - 你可以写When I send a request with a valid phone number and the amount "-1.0"
    • 不错的答案,我肯定会第二个@perfectist 并把你推倒选项 d。只是选择示例来充实您的测试,而不是详尽地测试每个可能的组合。如果您需要详尽的测试,请连接一些可以生成组合测试的东西(请参阅 mbUnit),或者可能只是一个重新使用您的 Specflow 绑定的控制台应用程序......
    • 感谢@perfectist,非常感谢您的回答;它绝对是完整和详尽的。
    猜你喜欢
    • 2018-03-10
    • 2014-10-12
    • 2021-04-29
    • 2016-01-25
    • 2015-01-29
    • 2020-03-10
    • 1970-01-01
    • 2015-11-23
    • 1970-01-01
    相关资源
    最近更新 更多