Cucumber:场景大纲重用示例表

2022-01-22 00:00:00 integration-testing cucumber java

我有一些测试如下:

Scenario Outline: Add two numebrs
  Given two numbers <number_1> and <number_2>
  When I add them
  Then Result is <number_3>

  Examples:
    |number_1|number_2|number_3|
    |2       |3       |5       |
    |1       |2       |3       |

Scenario Outline: Update two numebrs
  Given two numbers <number_1> and <number_2>
  When I update them
  Then Result is <number_3>

  Examples:
    |number_1|number_2|number_3|
    |2       |3       |5       |
    |1       |2       |3       |

对于每个测试,我应该添加相同的表格示例.

For each test I should add the same table Examples.

有什么方法可以提取此表以对所有测试使用同一个表?

Is any way to extract this table to use the same one for all tests?

推荐答案

你可以使用 qaf-gherkin 您可以在其中移动外部文件中的示例并将其用于一个或多个场景.使用 qaf,您的功能文件可能如下所示:

You can use qaf-gherkin where you can move examples in external file and use it with one or more scenario. With qaf your feature file may look like below:

Scenario Outline: Add two numebrs
  Given two numbers <number_1> and <number_2>
  When I add them
  Then Result is <number_3>

  Examples::{'datafile':'resources/testdata.txt'}

Scenario Outline: Update two numebrs
  Given two numbers <number_1> and <number_2>
  When I update them
  Then Result is <number_3>
  Examples:{'datafile':'resources/testdata.txt'}

您的数据文件将如下所示:

And your datafile will look like:

  #col.separator=|
  number_1|number_2|number_3
  2|3|5       
  1|2|3       

以上是带有 | 的 csv(宪章分隔值)数据提供者的示例作为分隔符.您还可以使用不同的数据提供者来提供来自任何 excel/xml/json/database 的数据.

Above is example of csv (charter separated values) data provider with | as seperator. You also can use different data providers to provide data from any of excel/xml/json/database.

qaf-cucumber 有 BDD2 支持可与 Cumber 5 一起使用的黄瓜.

qaf-cucumber has BDD2 support with cucumber that can be used with Cumber 5.

相关文章