Specflow中的多维场景概述

g.c*_*lia 8 bdd cucumber specflow gherkin

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

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     |
    | ......... | ..........                      | ....   |
Run Code Online (Sandbox Code Playgroud)

Examples表提供了我需要的测试数据但是我会添加另一个Examples表,只包含运算符的名称(而不是MyOperatorName),以便为不同的运算符复制测试

Examples: 
   | operator  |
   | op_numb_1 |
   | op_numb_2 |
   | op_numb_3 |
Run Code Online (Sandbox Code Playgroud)

为了避免重复相同的情景大纲三次; 我知道这是不可能的,但我想知道什么是避免在功能内部使用三个不同的场景轮廓的最佳方法,除了运营商名称之外,它们是完全相同的.我知道我可以重复使用相同的步骤定义,但我试图了解是否有最佳实践可以防止在功能过于相似的情况下使功能混乱.

per*_*ist 10

很高兴你知道这是不可能的...那么有什么选择?好像有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 |
 | ......... | ..........                      | ....   | ...       | 
Run Code Online (Sandbox Code Playgroud)

湾 使用输入行表重复每个操作符的方案 - 但是您说您不想这样做.

C.使用运算符表重复每个输入行的方案 - 我喜欢这个选项,因为每个规则都是一个单独的测试.如果您真的,确实希望确保"运算符"策略的每个不同实现在相同的验证方案中通过并失败,那么为什么不将每个验证方案编写为单个方案大纲:例如

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...
Run Code Online (Sandbox Code Playgroud)

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

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

  • 不错的回答,我绝对是第二个@perfectionist,并推动你选择d.只是选择示例来充实您的测试,而不是详尽地测试每个可能的组合.如果您需要进行详尽的测试,然后连接可以生成组合测试的东西(请参阅mbUnit),或者只是重新使用Specflow绑定的控制台应用程序... (2认同)