空手道Java API用于Match方法 [英] Karate Java API for Match methods

查看:52
本文介绍了空手道Java API用于Match方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

我注意到Twitter上有关空手道的Java API的有趣帖子: https://twitter.com/ptrthomas/status/1344290316212342784

I noticed this interesting post on Twitter about a Java API for Karate: https://twitter.com/ptrthomas/status/1344290316212342784

我没有Twitter帐户,因此无法回复-希望您不要介意我在这里提问.

I don't have a twitter account so unable to reply - hope you don't mind me asking here instead.

我在一个工作项目中使用了空手道(与并行运行程序,功能文件等一起使用),使用起来很有趣-复杂的JSON断言给工作场所的一些人留下了深刻的印象.我们正在实现该项目的JSON响应字段覆盖范围,而其他框架(IMO)则无法实现.

I have used Karate (with the parallel runner, feature files and all) in one work project and it is a joy to use - and a few folks in the workplace are very impressed with the complex JSON assertion. We are achieving a level of JSON response field coverage for that project that is not possible with other frameworks (IMO).

我现在的任务是改进一个较旧的测试项目,该项目使用JUnit + RESTAssured,但字段声明非常有限.我无法将其完全转换为原始的空手道(太多的测试,没有足够的时间),但是我热衷于探索用上述Twitter文章中提到的空手道Java API补充现有功能的可能性.

I've now been tasked with improving an older test project which uses JUnit + RESTAssured, but has quite limited field assertions. I am unable to fully convert it to raw Karate (too many tests, not enough time), but I'm keen to explore the possibility of supplementing what is there already with the Karate Java API mentioned in above twitter post.

例如-对于使用RESTAssured获得响应的现有测试,以某种方式在空手道中使用包含"方法(或Match类中的任何方法)来声明该响应对我来说是一件好事,因为它是我遇到过的最好的JSON断言工具.

For example - for an existing test which gets a Response using RESTAssured, it would be nice for me to somehow use the 'contains' method (or any of the methods in Match class) in Karate to assert that response, as it is the best JSON assertion tool I have come across.

问题:

  1. 立即使用-您会为我的用例推荐这种做法吗?让我知道您是否认为这是一种反模式.我问这个问题是因为这里的示例( https://github.com/ptrthomas/karate-showcase)没有使用RESTAssured来获得响应,而我的用例则有所不同.
  2. 如果值得探讨-我认为此内容将在v1.0.0中可用?(我看到诸如 that 之类的公共方法位于开发分支上,但在v1.0.0 github线程上看不到它.)
  1. Off the bat - is this a practice you would recommend for my use case? Let me know if you think this is an anti-pattern. I ask this because the example here (https://github.com/ptrthomas/karate-showcase) is not using RESTAssured to get the response and my use case is a bit different.
  2. If its worth exploring - I assume this stuff will be available in v1.0.0? (I see public methods such as that are on the develop branch, but couldn't see it on the v1.0.0 github thread).

推荐答案

但是我热衷于探索用上面的Twitter文章中提到的Karate Java API补充已有功能的可能性.

but I'm keen to explore the possibility of supplementing what is there already with the Karate Java API mentioned in above twitter post.

这非常有趣,您也让我也考虑了将空手道引入旧项目的这种潜在有趣的方式.我确实对如何魔术地迁移现有RA测试有很多疑问.

That's very interesting and you have got me also thinking about this potentially interesting way to introduce Karate to legacy projects. I do get this question on how to magically migrate existing RA tests a lot.

我会推荐.您可以期望下周出现0.9.9.RC3,其中应该包含您想要的所有断言.而且API已简化,因此您无需调用 isTrue()等.

I would recommend it. You can expect a 0.9.9.RC3 next week that should have all the assertions you want. And the API has been simplified so you don't need to call isTrue() etc.

我们计划有更好的示例(也许您可以提供帮助),但是现在,以它为起点(查看最后一个测试/文件的结尾):

We plan to have better examples (maybe you can help) but for now, use this as a starting point (look at the last test / very end of the file): MatchTest.java

如果您想立即开始(我建议您可以提供更多反馈),请查看开发人员指南:

If you want to get started now (which I recommend and you can provide more feedback) do take a look at the developer guide: https://github.com/intuit/karate/wiki/Developer-Guide

这篇关于空手道Java API用于Match方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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