空手道-能够对csv文件中的特定数据集执行测试 [英] Karate - Ability to execute tests on a specific set of data in a csv file

查看:94
本文介绍了空手道-能够对csv文件中的特定数据集执行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个团队中,向我们展示空手道的优势,使其成为我们API测试的首选框架.但是,关于数据驱动的测试,我遇到了几个问题.

我已经阅读了文档 csv文件,并且找不到以下问题的解决方案:

  1. 空手道是否能够对csv文件中给出的特定数据集(例如,基于优先级p0,p1)执行测试?

示例"test.csv":

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

我想用csv文件(p0或p1或两者)中的特定数据集运行我的测试用例.空手道有能力做到这一点吗?

解决方案

我可以通过多种方式执行此操作,这是一种方法:

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 |

您不需要强迫自己进入Scenario Outline,您可以循环访问数据并忽略不需要进行任何处理的行.

有关更多建议,请参考此答案: https://stackoverflow.com/a/61685169/143475

请注意,您可以后退"到Java以获取高级逻辑(如果需要): https://github.com/intuit/karate#calling- Java

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?

解决方案

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

这篇关于空手道-能够对csv文件中的特定数据集执行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆