Scenario Outline关键字可用于以不同的值组合多次运行相同的方案。
当参数为表时,如何使用“方案大纲”简化多个方案。
Scenario: 1 row
Given I import data to a table
| col1 | col2 |
| value1-1 | value1-2 |
When I execuate the logic1
Then I can get data
| result_col1 | result_col2 |
| result-value1-1 | result-value1-2 |
Scenario: 2 rows
Given I import data to a table
| col1 | col2 |
| value1-1 | value1-2 |
| value2-1 | value2-2 |
When I execuate the logic1
Then I can get data
| result_col1 | result_col2 |
| result-value1-1 | result-value1-2 |
Scenario: 3 rows
Given I import data to a table
| col1 | col2 |
| value1-1 | value1-2 |
| value2-1 | value2-2 |
| value3-1 | value3-2 |
When I execuate the logic1
Then I can get data
| result_col1 | result_col2 |
| result-value1-1 | result-value1-2 |
| result-value3-1 | result-value3-2 |
答案 0 :(得分:0)
您在各列中使用相同的步骤和相同的期望值。
您可以使用方案大纲进行以下简化:
Scenario Outline: Example Scenario Outline
Given that the user import the following data to a table
| Col1 | Col2 |
| <Col1> | <Col2> |
When the user perform the logic action
Then I can get data "<Result_col1>" and "<Result_col2>"
Examples:
| Id | Scenario | Col1 | Col2 | result_col1 | result_col2 |
| 1 | value1-1 | value1-1 | value1-2 | result-value1-1 | result-value1-2 |
| 2 | value2-1 | value2-1 | value2-2 | result-value2-1 | result-value2-2 |
注意:在您的代码中,您可以使用Jackson的值作为列表或数据表,您可以在步骤和Dto类中创建不同的DTO映射数据
@Given("^that the user import the following data to a table$")
public void that_the_user_import_the_following_data_to_a_table(DataTable yourClassExampleDTO) throws Throwable {
List<YourClassExampleDTO> lstYourClassExampleDTO = yourClassExampleDTO.asList(YourClassExampleDTO.class);
int lstSize = lstYourClassExampleDTO.size();
for (int i = 0; i < lstSize; i++) {
lstYourClassExampleDTO.get(i);
}
}