首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用场景大纲简化多个场景

使用场景大纲简化多个场景
EN

Stack Overflow用户
提问于 2019-08-26 18:12:37
回答 1查看 60关注 0票数 0

Scenario Outline关键字可用于使用不同的值组合多次运行同一方案。

当参数是表格时,如何使用场景大纲来简化多个场景。

代码语言:javascript
复制
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 |
EN

回答 1

Stack Overflow用户

发布于 2019-08-30 06:04:05

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

您可以使用Scenario Outline进行简化,如下所示:

代码语言:javascript
复制
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,并映射steps和Dto类中的数据

代码语言:javascript
复制
    @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);

        }

    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57655888

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档