Cucumber 小黄瓜情景大纲还是多种情景?

Cucumber 小黄瓜情景大纲还是多种情景?,cucumber,bdd,specflow,gherkin,Cucumber,Bdd,Specflow,Gherkin,在为BDD定义小黄瓜格式的验收标准时,是否有首选方法 我是否应该将场景分为以下几部分 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 de

在为BDD定义小黄瓜格式的验收标准时,是否有首选方法

我是否应该将场景分为以下几部分

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 |
场景:用户保存联系人详细信息
因为我在联系方式页面上
当我输入以下详细信息时
|电子邮件|电话|
|  |  |
我保存细节
然后正确保存详细信息
示例:
|电子邮件|电话|
| pete@gmail.com                                                | 012345678             |
| peterpeterperterlongemailaddress1234567890@gmailsomething.com | 012345678             |
| pete@gmail.com                                                | 012345678901234567890 |
后者可能更容易适应/添加,但对我来说,它失去了场景的基本概念

更新 我刚刚看到下面这篇文章,它讨论了这一点。建议采用后者是更好的方法。

它建议如下:

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 |
场景:用户保存联系人详细信息
因为我在联系方式页面上
当我输入以下详细信息时
|电子邮件|电话|
|  |  |
我保存细节
然后正确保存详细信息
示例:
|场景|电子邮件|电话|
|已保存基本详细信息|pete@gmail.com                                                | 012345678             |
|很长的电子邮件地址|peterpeterperterlongemailaddress1234567890@gmailsomething.com | 012345678             |
|很长的电话号码|pete@gmail.com                                                | 012345678901234567890 |

一般来说,如果您改变了输入,但期望相同的输出,那么您就有了一个很好的场景大纲

您可以参数化
然后
步骤,但我建议不要这样做,因为更改测试的断言意味着您已经从根本上更改了测试。这是一个哲学和代码维护问题

考虑电话号码的最大长度,根据您的示例,该长度应为11个字符。如果最多11个字符,并且您有一个测试该边界两侧的场景大纲,那么该场景有多个失败原因。首先,当11不再是最大长度时,而且如果12现在是最大长度,该测试也将失败

有多种失败原因的测试是“脆弱的”

下面的场景大纲改变了断言和输入,这意味着该测试有多种失败原因

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   |
场景大纲:用户保存联系人详细信息
因为我在联系方式页面上
当我输入以下详细信息时
|电子邮件|电话|
| pete@gmail.com |  |
我保存细节
然后正确保存详细信息
示例:
|电话|断言|
|012345678901234567890 |是|
|0123456789012345678901 |不是|
我甚至建议将电子邮件场景与电话号码场景分开

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

下面的两个场景看起来是彼此重复的,但是保持大部分输入的一致性,并且只改变其中一个输入,可以提供更稳定的测试,这些测试失败的原因显而易见:

Scenario Outline: User saves contact phone number
    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 are correctly saved

Examples:
    | Phone                 |
    | 012345678             |
    | 012345678901234567890 |

Scenario Outline: User saves contact e-mail address
    Given I am on the contact details page
    When I enter the following details
        | email   | phone     |
        | <Email> | 012345678 |
    And I save the details
    Then the details are correctly saved

Examples:
    | Email                                                         |
    | pete@gmail.com                                                |
    | peterpeterperterlongemailaddress1234567890@gmailsomething.com |
场景大纲:用户保存联系人电话号码
因为我在联系方式页面上
当我输入以下详细信息时
|电子邮件|电话|
| pete@gmail.com |  |
我保存细节
然后正确保存详细信息
示例:
|电话|
| 012345678             |
| 012345678901234567890 |
场景概述:用户保存联系人电子邮件地址
因为我在联系方式页面上
当我输入以下详细信息时
|电子邮件|电话|
|  | 012345678 |
我保存细节
然后正确保存详细信息
示例:
|电子邮件|
| pete@gmail.com                                                |
| peterpeterperterlongemailaddress1234567890@gmailsomething.com |

现在,当一个方案失败时,方案名称会提示您应用程序的哪个部分可能是错误的,这有助于调试。

非常好的建议Greg-非常有用。关于失败的多个原因的观点是当场的,谢谢!