Search code examples
cucumbercucumber-jvmkaratecucumber-java

Karate test framework: Only one assert using Examples


Suppose that I want to test if my api removes duplicated entries.

My current steps are:

1) Post the same JSON request several times using Examples, each request in a different scenario:

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

Examples:
  | field1 |
  | value1 |
  | value1 |

2) Assert in a new scenario that there are not duplicates:

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

Problem here is that I suspect that scenarios order is not guaranteed. Is there any approach to solve this problem without "unrolling" the loop (see example below)?

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: My real use case requires at least 20 entries in Examples to fill a very large JSON, so "unrolling" the loop is not a solution.

Thanks in advance.


Solution

  • Try the alternate form of data-driven tests as described here: https://github.com/intuit/karate#data-driven-features

    So you can have a second feature file, and call it for the "loop" and after the loop, perform the assertion you want.