空手道测试框架:仅使用示例一个断言

时间:2019-04-27 00:23:35

标签: cucumber cucumber-jvm karate cucumber-java

假设我要测试我的api是否删除重复的条目。

我当前的步骤是:

1)使用示例多次发布相同的JSON请求,每个请求在不同的情况下:

Scenario Outline:
Given path '/endpoint'
And request
"""
{
  "field1": <field1>
}
"""
When method post
Then status 200

Examples:
  | field1 |
  | value1 |
  | value1 |

2)在新场景中声明没有重复项:

Scenario:
Given path '/other_endpoint'
When method get
Then match response.values == [ "value1" ]

这里的问题是我怀疑方案的顺序不能保证。有没有解决此问题的方法而无需“展开”循环(请参见下面的示例)?

Scenario:
Given path '/endpoint'
And request
"""
{
  "field1": value1
}
"""
When method post
Then status 200

Given path '/endpoint'
And request
"""
{
  "field1": value1
}
"""
When method post
Then status 200

Given path '/other_endpoint'
When method get
Then match response.values == [ "value1" ]

PD:我的实际用例在“示例”中至少需要20个条目才能填充非常大的JSON,因此“展开”循环不是解决方案。

谢谢。

1 个答案:

答案 0 :(得分:2)

尝试按如下所述尝试使用其他形式的数据驱动测试:https://github.com/intuit/karate#data-driven-features

因此,您可以拥有另一个功能文件,并将其称为“循环”,然后在循环之后执行所需的断言。