如何在空手道中使用特定于环境的测试数据 [英] How to use environment specific test data in Karate

查看:48
本文介绍了如何在空手道中使用特定于环境的测试数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在各种环境中执行测试时,如何在运行时使用不同的数据集.我已经阅读了文档,但是找不到适用于这种情况的最佳解决方案.

I would like to know how it is possible to use different data sets on runtime when executing tests in various environments. I have read the documentation but i am unable to find the best solution for this scenario.

要求:在QA环境中执行测试,然后在SIT中执行相同的测试.但是,请在请求中使用其他数据,例如customerIds.这样做的原因是因为每种环境中的数据设置都非常不同.

Requirement: Execute a test in QA environment and then execute the same test in SIT. However, use different data in the request e.g customerIds. The reason for this is because the data setup in each environment is very different.

如果您能针对这种情况提出最佳解决方案,将不胜感激.

Would appreciate it if you could propose the best solution for this scenario.

推荐答案

在文档中,您可以找到有关如何执行此操作的说明: https://github.com/intuit/karate#environment-specific-config

Here in the documentation, you can find an explanation on how to do this : https://github.com/intuit/karate#environment-specific-config

然后,您可以在启动空手道时简单地指定环境:

Then you can simply specify the environment when launching karate :

mvn test -DargLine="-Dkarate.env=e2e"

您的所有测试都将能够使用您为指定环境定义的变量.

And all your tests will be able to use the variables you've defined for the specified environment.

另一个提示,在您的配置文件中,指定文件的路径.现在,根据您的环境,您将能够读取包含所有数据的其他文件.

another hint, in your config file, specify the path of a file. Now, depending on your env, you'll be able to read a different file, containing all your data.

在评论后假设您定义了两个环境,"qa"和"prod".对于两者之间存在差异的每个数据,只需创建两个文件: myFile-qa.json myFile-prod.json .

Edit after your comment : Let's say you defined two environments, "qa" and "prod". For every data where there is a difference between the two, simply create two files : myFile-qa.json and myFile-prod.json.

现在,在测试中,当您想读取文件时,只需阅读('myFile-'+ env +'.json').就像这样,您将根据定义的环境读取正确的文件.

Now, in your tests, when you want to read a file, just read ('myFile-'+env+'.json'). And just like that, you read the correct file depending on your defined environment.

这篇关于如何在空手道中使用特定于环境的测试数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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