小黄瓜方案大纲还是多个方案?

时间:2019-08-07 11:12:49

标签: cucumber bdd specflow gherkin

在为BDD定义Gherkin格式的接受标准时,是否存在首选方法?

我应该按如下方式分解方案...

Scenario: User saves contact details
Given I am on the contact details page
When I enter the following details
| email          | phone     |
| pete@gmail.com | 012345678 |
And I save the details
Then the details are correctly saved

Scenario: User saves contact details with a very long email address
Given I am on the contact details page
When I enter the following details
| email                                                         | phone     |
| peterpeterperterlongemailaddress1234567890@gmailsomething.com | 012345678 |
And I save the details
Then the details are correctly saved

Scenario: User saves contact details with a very long phone number

etc

还是应该使用具有多个轮廓的单个方案?

Scenario: User saves contact details
Given I am on the contact details page
When I enter the following details
| email   | phone   |
| <email> | <phone> |
And I save the details
Then the details are correctly saved

Examples: 
| email                                                         | phone                 |
| pete@gmail.com                                                | 012345678             |
| peterpeterperterlongemailaddress1234567890@gmailsomething.com | 012345678             |
| pete@gmail.com                                                | 012345678901234567890 |

后者可能更容易适应/添加,但对我来说却失去了场景的基本概念。

更新 我刚刚看了下面的文章,它讨论了这一点。建议后者是一种更好的方法。 https://www.hindsightsoftware.com/blog/scenario-outlines

它建议如下内容:

Scenario: User saves contact details
Given I am on the contact details page
When I enter the following details
| email   | phone   |
| <email> | <phone> |
And I save the details
Then the details are correctly saved

Examples: 
| scenario                  | email                                                         | phone                 |
| basic details saved       | pete@gmail.com                                                | 012345678             |
| very long email address   | peterpeterperterlongemailaddress1234567890@gmailsomething.com | 012345678             |
| very long phone number    | pete@gmail.com                                                | 012345678901234567890 |

1 个答案:

答案 0 :(得分:2)

通常,如果您改变输入,但是期望获得相同的输出,那么就可以很好地说明场景。

您可以参数化inputCheck(target,key){ let column = target%COLUMNSIZE; let row = Math.floor(target/COLUMNSIZE); let isBack = key == "Backspace" && column != 0 this.inputs[row*COLUMNSIZE+column].setNativeProps({ text: isBack ? "" : this.key }) if(column< COLUMNSIZE-1){ this.inputs[row*COLUMNSIZE+column+(isBack?-1:1 )].focus() //Backspace bitince ileri gidiyor fixle }else{ let checkingValue = ""; for (let i = 0; i < COLUMNSIZE; i++) { checkingValue += this.inputs[row*COLUMNSIZE+i]._lastNativeText console.log(checkingValue) } if(this.state.words[row] === checkingValue){ for (let i = 0; i < COLUMNSIZE; i++) { //this.inputs[row*COLUMNSIZE+i].disable = false; } this.inputs[row*COLUMNSIZE+COLUMNSIZE].focus(); }else{ for (let i = 0; i < COLUMNSIZE; i++) { this.inputs[row*COLUMNSIZE+i].clear(); } this.inputs[row*COLUMNSIZE].focus(); } } } 步骤,但是我建议不要这样做,因为更改测试的断言意味着您从根本上更改了测试。这是一个哲学和代码维护问题。

请考虑电话号码的最大长度,在您的示例中,该长度应为11个字符。如果最多11个字符,并且您有一个测试大纲边界两端的方案大纲,则该方案有多个失败原因。首先,当11不再是最大长度时,并且如果现在12是最大长度,则该测试也将失败。

由于多种原因导致测试失败的测试是“不稳定”

下面的方案大纲会改变声明和输入,这意味着该测试有多个失败原因。

Then

我什至建议将电子邮件方案与电话号码方案分开。

每次测试都只有一个失败的原因。

以下两种情况似乎是彼此重复的,但是要使大多数输入保持一致,并且只有改变其中一种输入才能使您进行更稳定的测试,但由于明显的原因而失败:

Scenario Outline: User saves contact details
    Given I am on the contact details page
    When I enter the following details
        | email          | phone   |
        | pete@gmail.com | <Phone> |
    And I save the details
    Then the details <Assertion> correctly saved

Examples:
    | Phone                  | Assertion |
    | 012345678901234567890  | Are       |
    | 0123456789012345678901 | Are Not   |

现在,当方案失败时,方案名称会提示您应归咎于应用程序的哪一部分,这有助于调试。

相关问题