空手道测试框架中是否提供数值比较? [英] Is there numeric value comparison available in Karate testing framework?

查看:18
本文介绍了空手道测试框架中是否提供数值比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经历了各种验证空手道框架的断言.我没有找到任何功能来比较数值作为响应.下面是一些例子.

I gone through various validation and Assertion of karate framework. I did not found any functionality to compare numeric values in response. Below are some examples.

  • 1.00 和 1.0 应该相等
  • 1 和 1.00 相等

现在只有字符串比较,所以上面的值是不相等的,因为它们不同的是字符串格式.

Right now there is only string comparison, so above values are giving as not equal as they are different is string format.

推荐答案

当然,如果你尝试比较两个字符串,它会有所不同!空手道处理数字非常好,看起来你没有正确阅读文档或示例.

Of course if you try to compare two strings, it will be different ! Karate handles numbers perfectly well, looks like you haven't read the documentation or examples properly.

* def a = 1
* def b = 1.0
* match a == b

如果您的 JSON 响应以字符串形式出现,并且您确实想将它们作为数字进行比较,则需要对其进行转换.请参阅此处的文档:https://github.com/intuit/karate#floats-和-整数

If your JSON responses are coming as strings, and you really want to compare them as numbers, you need to convert them. Refer to the docs here: https://github.com/intuit/karate#floats-and-integers

* def a = 1
* def b = '1.0'
* match a == b * 1
* match a == ~~b

这篇关于空手道测试框架中是否提供数值比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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