如何将数据库中的字符串值与响应中的整数值相匹配

时间:2019-02-07 03:29:58

标签: karate

我的功能调用Java来查询数据库,然后将结果与响应进行比较。 Java调用的结果以字符串形式返回所有值。但是在响应中,某些值是整数。因此测试失败的原因是:实际值不是字符串。我试图将结果转换为json,但是没有用。如果我打印出结果,它将显示所有键和值都用双引号引起来,但是错误消息中没有双引号。我在论坛中发现了类似的问题,建议将响应中的字段设置为“ #ignore”。但我想验证所有字段。如何使它工作?

Scenario: Get an script by id
* def results = db.getRows("select * from ScriptVersion where id=4 order by version")

Given path '4'
When method get
Then status 200
And match response.version == results  

[main] ERROR com.intuit.karate - assertion failed: path: $.version[0], actual: {id=4, version=1, created=2016-06-23T10:49:51.9630000-05:00, updated=2016-06-23T10:49:51.9630000-05:00, message=Initial Version, author=ocadm, hash=0023ad00455962eee4ef1db16a58ce41}, expected: {created=2016-06-23T10:49:51.9630000-05:00, author=ocadm, id=4, message=Initial Version, version=1, updated=2016-06-23T10:49:51.9630000-05:00, hash=0023ad00455962eee4ef1db16a58ce41}, reason: [path: $.version[0].id, actual: 4, expected: '4', reason: actual value is not a string]

1 个答案:

答案 0 :(得分:1)

只需在select student_id, student_name, max(case when course_name='english' then subscribed end) as english, max(case when course_name='arabic' then subscribed end) as arabic, max(case when course_name='chinese' then subscribed end) as chinese from tablename group by student_id, student_name 之前将所需的字段转换为正确的数据类型:

match