Karate - Ability to execute tests on a specific set of data in a csv file

会有一股神秘感。 提交于 2021-01-28 08:10:21

问题


I am on a team, presenting the advantages of Karate to move forward as the framework of choice for our API testing. However, I have come across a couple questions, in regards to data-driven testing.

I have gone through the documentation, csv files and cannot find a solution for this question:

  1. Is Karate capable of executing tests on specific data sets (For instance, based on priority p0, p1) given in a csv file?

Example "test.csv":

|priority|data1|
| p0     |  1  |  
| p0     |  2  |
| p1     |  4  |
| p1     |  6  |

I want to run my test cases with specific data sets in a csv file (p0, or p1, or both). Is Karate capable of this?


回答1:


There are multiple ways I would do this, here is one:

Background:
* def data = read('test.csv')
* def selected = 'p1'
* def fun = function(x){ return x.priority == selected }
* def filtered = karate.filter(data, fun)

Scenario Outline:
* print __row

Examples:
| filtered |

You don't need to force yourself into a Scenario Outline, you can loop over data and ignore the rows where you don't want to do any processing.

Refer to this answer for more ideas: https://stackoverflow.com/a/61685169/143475

Note that you can "fall back" to Java for advanced logic if needed: https://github.com/intuit/karate#calling-java



来源:https://stackoverflow.com/questions/63387913/karate-ability-to-execute-tests-on-a-specific-set-of-data-in-a-csv-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!