【问题标题】:Simplify multiple Scenarios with Scenario Outline使用场景大纲简化多个场景
【发布时间】:2019-08-26 10:12:37
【问题描述】:

Scenario Outline 关键字可用于多次运行相同的场景,使用不同的值组合。

当参数为表格时,如何使用 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 |

【问题讨论】:

    标签: cucumber-java cucumber-junit


    【解决方案1】:

    您在列中使用相同的步骤和相同的预期值。

    您可以使用 Scenario Outline 简化如下:

    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);
    
            }
    
        }
    

    【讨论】:

      猜你喜欢
      • 2018-03-10
      • 2019-12-15
      • 2020-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-12
      相关资源
      最近更新 更多