How to prepare a nested data structure for a data-driven test in Karate?

前端 未结 1 1485
攒了一身酷
攒了一身酷 2020-12-11 12:13

I currently use junit5, wiremock and restassured for my integration tests. Karate looks very promising, yet I am struggling with the setup of data-driven tests a bit as I ne

相关标签:
1条回答
  • 2020-12-11 12:26

    I don't recommend nesting unless absolutely necessary. You may be able to "flatten" your permutations into a single table, something like this: https://github.com/intuit/karate/issues/661#issue-402624580

    That said, look out for the alternate option to Examples: which just might work for your case: https://github.com/intuit/karate#data-driven-features

    Here's a simple example:

    Feature:
    
    Scenario:
    * def data = [{ rows: [{a: 1},{a: 2}] }, { rows: [{a: 3},{a: 4}] }]
    * call read('called.feature@one') data
    

    and this is: called.feature:

    @ignore
    Feature:
    
    @one
    Scenario:
    * print 'one:', __loop
    * call read('called.feature@two') rows
    
    @two
    Scenario:
    * print 'two:', __loop
    * print 'value of a:', a
    

    This is how it looks like in the new HTML report (which is in 0.9.6.RC2 and may need more fine tuning) and it shows off how Karate can support "nesting" even in the report, which Cucumber cannot do. Maybe you can provide feedback and let us know if it is ready for release :)

    0 讨论(0)
提交回复
热议问题