空手道测试框架中是否提供数值比较?空手道、数值、框架、测试

2023-09-07 23:38:43 作者:笑迎怀羞

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

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