2013-10-31 29 views
8

我创建一个方案概述类似于下面的一个(这是一个简化版本,但给我的问题的一个很好的迹象):的多维场景勾勒出Specflow

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  | 
    | ......... | ..........      | .... | 

的例子表提供了测试数据,我需要,但我会以复制测试不同的运营商

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

,以避免重复同样的场景轮廓三次添加另一个示例表与运营商(而不是MyOperatorName)只是名称;我知道这是不可能的,但我想知道什么是最好的方法来避免使用三个不同的场景轮廓内的功能,除了运营商名称相同。 我知道我可以重复使用相同的步骤定义,但我试图了解是否有一个最佳做法,以防止与太相似的场景混淆功能。

回答

8

很高兴你知道这是不可能的... 那么有什么选择? 好像有5:

一个:使一个表,每一个选项(叉积)

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 | 
| ......... | ..........      | .... | ...  | 

湾对每个操作员重复场景,输入行的表格为 - 但是您说过您不想这样做。

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... 

d。重新思考你如何使用Specflow - 如果你只需要关键的例子来说明你的特征(如Gojko Adzic的例子说明所描述的那样),那么你通过检查每个组合来做到过度。但是,如果您使用specflow来自动执行全套集成测试,那么您的场景可能是合适的......但您可能需要考虑e。

e。编写集成/单元测试的基础是您的“操作员”验证逻辑仅适用于一个地方。如果每个运算符的验证都是相同的,那么为什么不测试一次,然后让所有运算符都继承自或构成相同的验证器类?

+1

公平地说,'当我为操作员提供有效的电话号码'在选项c中是多余的。 - 你可以写'当我用一个有效的电话号码和金额“-1.0”发送请求时。 – perfectionist

+2

好的答案,我肯定会再次@完美主义者,并推低选项d。只是选择范例来充实你的测试,而不是详尽地测试每种可能的组合。如果你需要详尽的测试,然后连接一些可以产生组合测试的东西(请参阅mbUnit),或者只是一个控制台应用程序,重新使用您的Specflow绑定... – AlSki

+0

感谢@perfectionist,我真的很感谢你的答案;它绝对是完整和详尽的。 –