Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cucumber SpecFlow/Gherkin-是否可以在多个“文件”中使用相同的示例;尺寸;?_Cucumber_Bdd_Specflow_Gherkin - Fatal编程技术网

Cucumber SpecFlow/Gherkin-是否可以在多个“文件”中使用相同的示例;尺寸;?

Cucumber SpecFlow/Gherkin-是否可以在多个“文件”中使用相同的示例;尺寸;?,cucumber,bdd,specflow,gherkin,Cucumber,Bdd,Specflow,Gherkin,下面是一个简单的场景大纲: Scenario Outline: Add two numbers Given I have entered <firstNumber> into the calculator And I have entered <secondNumber> into the calculator When I press <button> Then the result should be <expecte

下面是一个简单的场景大纲:

Scenario Outline: Add two numbers
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    When I press <button>
    Then the result should be <expectedResult> on the screen
Scenarios: 
    | firstNumber | secondNumber | button | expectedResult |
    | 1           | 2            | plus   | 3              |
    | 2           | 2            | plus   | 4              |
    | 4           | 5            | plus   | 9              |
场景大纲:添加两个数字
假设我已经输入了计算器
我已经输入了计算器
当我按下
然后结果应该显示在屏幕上
情节:
|第一个数字|第二个数字|按钮|预期结果|
|1 | 2 |加| 3|
|2 | 2 |加4|
|4 | 5 |加9|
我希望在多组其他条件下运行这些测试数据。我可以这样做:

Scenario Outline: Add two numbers
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    When I press <button>
    Then the result should be <expectedResult> on the screen
Scenarios: 
    | firstNumber | secondNumber | button | expectedResult |
    | 1           | 2            | plus   | 3              |
    | 2           | 2            | plus   | 4              |
    | 4           | 5            | plus   | 9              |
    | 1           | 2            | add    | 3              |
    | 2           | 2            | add    | 4              |
    | 4           | 5            | add    | 9              |
    | 1           | 2            | +      | 3              |
    | 2           | 2            | +      | 4              |
    | 4           | 5            | +      | 9              |
Scenario Outline: Add two numbers (plus)
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    When I press plus
    Then the result should be <expectedResult> on the screen
Scenarios: 
    | firstNumber | secondNumber | expectedResult |
    | 1           | 2            | 3              |
    | 2           | 2            | 4              |
    | 4           | 5            | 9              |

Scenario Outline: Add two numbers (+)
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    When I press +
    Then the result should be <expectedResult> on the screen
Scenarios: 
    | firstNumber | secondNumber | expectedResult |
    | 1           | 2            | 3              |
    | 2           | 2            | 4              |
    | 4           | 5            | 9              |

Scenario Outline: Add two numbers (add)
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    When I press add
    Then the result should be <expectedResult> on the screen
Scenarios: 
    | firstNumber | secondNumber | expectedResult |
    | 1           | 2            | 3              |
    | 2           | 2            | 4              |
    | 4           | 5            | 9              |
Scenario Outline: Add two numbers
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    When I press
        | button |
        | plus   |
        | +      |
        | add    |
    Then the result should be <expectedResult> on the screen
Scenarios: 
    | firstNumber | secondNumber | expectedResult |
    | 1           | 2            | 3              |
    | 2           | 2            | 4              |
    | 4           | 5            | 9              |
场景大纲:添加两个数字
假设我已经输入了计算器
我已经输入了计算器
当我按下
然后结果应该显示在屏幕上
情节:
|第一个数字|第二个数字|按钮|预期结果|
|1 | 2 |加| 3|
|2 | 2 |加4|
|4 | 5 |加9|
|1 | 2 |添加| 3|
|2 | 2 |添加| 4|
|4 | 5 |添加| 9|
| 1           | 2            | +      | 3              |
| 2           | 2            | +      | 4              |
| 4           | 5            | +      | 9              |
…或者像这样:

Scenario Outline: Add two numbers
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    When I press <button>
    Then the result should be <expectedResult> on the screen
Scenarios: 
    | firstNumber | secondNumber | button | expectedResult |
    | 1           | 2            | plus   | 3              |
    | 2           | 2            | plus   | 4              |
    | 4           | 5            | plus   | 9              |
    | 1           | 2            | add    | 3              |
    | 2           | 2            | add    | 4              |
    | 4           | 5            | add    | 9              |
    | 1           | 2            | +      | 3              |
    | 2           | 2            | +      | 4              |
    | 4           | 5            | +      | 9              |
Scenario Outline: Add two numbers (plus)
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    When I press plus
    Then the result should be <expectedResult> on the screen
Scenarios: 
    | firstNumber | secondNumber | expectedResult |
    | 1           | 2            | 3              |
    | 2           | 2            | 4              |
    | 4           | 5            | 9              |

Scenario Outline: Add two numbers (+)
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    When I press +
    Then the result should be <expectedResult> on the screen
Scenarios: 
    | firstNumber | secondNumber | expectedResult |
    | 1           | 2            | 3              |
    | 2           | 2            | 4              |
    | 4           | 5            | 9              |

Scenario Outline: Add two numbers (add)
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    When I press add
    Then the result should be <expectedResult> on the screen
Scenarios: 
    | firstNumber | secondNumber | expectedResult |
    | 1           | 2            | 3              |
    | 2           | 2            | 4              |
    | 4           | 5            | 9              |
Scenario Outline: Add two numbers
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    When I press
        | button |
        | plus   |
        | +      |
        | add    |
    Then the result should be <expectedResult> on the screen
Scenarios: 
    | firstNumber | secondNumber | expectedResult |
    | 1           | 2            | 3              |
    | 2           | 2            | 4              |
    | 4           | 5            | 9              |
场景大纲:添加两个数字(加号)
假设我已经输入了计算器
我已经输入了计算器
当我按下加号
然后结果应该显示在屏幕上
情节:
|第一个数字|第二个数字|预期结果|
| 1           | 2            | 3              |
| 2           | 2            | 4              |
| 4           | 5            | 9              |
场景大纲:添加两个数字(+)
假设我已经输入了计算器
我已经输入了计算器
当我按下+
然后结果应该显示在屏幕上
情节:
|第一个数字|第二个数字|预期结果|
| 1           | 2            | 3              |
| 2           | 2            | 4              |
| 4           | 5            | 9              |
场景大纲:添加两个数字(添加)
假设我已经输入了计算器
我已经输入了计算器
当我按add时
然后结果应该显示在屏幕上
情节:
|第一个数字|第二个数字|预期结果|
| 1           | 2            | 3              |
| 2           | 2            | 4              |
| 4           | 5            | 9              |
…但这两者都涉及大量重复。我真正想写的是这样的:

Scenario Outline: Add two numbers
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    When I press <button>
    Then the result should be <expectedResult> on the screen
Scenarios: 
    | firstNumber | secondNumber | button | expectedResult |
    | 1           | 2            | plus   | 3              |
    | 2           | 2            | plus   | 4              |
    | 4           | 5            | plus   | 9              |
    | 1           | 2            | add    | 3              |
    | 2           | 2            | add    | 4              |
    | 4           | 5            | add    | 9              |
    | 1           | 2            | +      | 3              |
    | 2           | 2            | +      | 4              |
    | 4           | 5            | +      | 9              |
Scenario Outline: Add two numbers (plus)
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    When I press plus
    Then the result should be <expectedResult> on the screen
Scenarios: 
    | firstNumber | secondNumber | expectedResult |
    | 1           | 2            | 3              |
    | 2           | 2            | 4              |
    | 4           | 5            | 9              |

Scenario Outline: Add two numbers (+)
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    When I press +
    Then the result should be <expectedResult> on the screen
Scenarios: 
    | firstNumber | secondNumber | expectedResult |
    | 1           | 2            | 3              |
    | 2           | 2            | 4              |
    | 4           | 5            | 9              |

Scenario Outline: Add two numbers (add)
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    When I press add
    Then the result should be <expectedResult> on the screen
Scenarios: 
    | firstNumber | secondNumber | expectedResult |
    | 1           | 2            | 3              |
    | 2           | 2            | 4              |
    | 4           | 5            | 9              |
Scenario Outline: Add two numbers
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    When I press
        | button |
        | plus   |
        | +      |
        | add    |
    Then the result should be <expectedResult> on the screen
Scenarios: 
    | firstNumber | secondNumber | expectedResult |
    | 1           | 2            | 3              |
    | 2           | 2            | 4              |
    | 4           | 5            | 9              |
场景大纲:添加两个数字
假设我已经输入了计算器
我已经输入了计算器
当我按下
|钮扣|
|加上|
| +      |
|加|
然后结果应该显示在屏幕上
情节:
|第一个数字|第二个数字|预期结果|
| 1           | 2            | 3              |
| 2           | 2            | 4              |
| 4           | 5            | 9              |
…并让每个场景对“按钮”的每个值执行“乘法”


有什么好办法吗?这里是一个可能的选择

Scenario Outline: Add two numbers
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    Then validate the <expectedResults> by clicking <buttons> button

    Scenarios:
      | firstNumber | secondNumber | buttons               | expectedResults |
      | 1           | 2            | plus,add,+,multiply,x | 3,3,3,2,2      |
      | 2           | 2            | plus,add,+,multiply,x | 4,4,4,4,4      |
      | 4           | 5            | plus,add,+,multiply,x | 9,9,9,20,20    |
场景大纲:添加两个数字
假设我已经输入了计算器
我已经输入了计算器
然后通过单击按钮验证
情节:
|第一个数字|第二个数字|按钮|预期结果|
|1 | 2 |加、加、乘、x | 3,3,2,2|
|2 | 2 |加、加、乘、x | 4,4,4,4|
|4 | 5 |加、加、乘、x | 9,9,20,20|
在步骤def中,使用
拆分
expectedResults
按钮
,然后比较数组长度。一旦数组长度匹配,然后根据两个数组的索引获取项,并执行以下两个选项之一

选项1:直接在步骤def中执行逻辑


选项2:当我按plus和
时调用步骤
,然后结果应显示在屏幕上
步骤中。

这里是一个可能的选项

Scenario Outline: Add two numbers
    Given I have entered <firstNumber> into the calculator
    And I have entered <secondNumber> into the calculator
    Then validate the <expectedResults> by clicking <buttons> button

    Scenarios:
      | firstNumber | secondNumber | buttons               | expectedResults |
      | 1           | 2            | plus,add,+,multiply,x | 3,3,3,2,2      |
      | 2           | 2            | plus,add,+,multiply,x | 4,4,4,4,4      |
      | 4           | 5            | plus,add,+,multiply,x | 9,9,9,20,20    |
场景大纲:添加两个数字
假设我已经输入了计算器
我已经输入了计算器
然后通过单击按钮验证
情节:
|第一个数字|第二个数字|按钮|预期结果|
|1 | 2 |加、加、乘、x | 3,3,2,2|
|2 | 2 |加、加、乘、x | 4,4,4,4|
|4 | 5 |加、加、乘、x | 9,9,20,20|
在步骤def中,使用
拆分
expectedResults
按钮
,然后比较数组长度。一旦数组长度匹配,然后根据两个数组的索引获取项,并执行以下两个选项之一

选项1:直接在步骤def中执行逻辑

选项2:当我按plus和
时调用步骤
,然后结果应显示在屏幕上
步骤中