groovy - 嵌套 json 中的断言计数
问题描述
我遵循 Katalon 代码以确保来自 API 的计数响应是正确的,但我收到了一个错误,所以我需要帮助来查看我的代码中缺少什么。
No signature of method: Script1568233794882.assertThat() is applicable for argument types: (java.lang.Integer) values: [29]
response text:
{
"Error": {
"A": {
"dependency": [
],
"duplicateRows": [
],
"requiredFieldRows": [
]
}
},
"Good": {
"A": {
"count": 29
},
"B": {
"count": 35
},
"C": {
"count": 37
}
},
"type": "Test"
}
我试过这个
def response = WS.sendRequest(requestObject)
def responseList = new JsonSlurper().parseText(response.getResponseText())
println('response text: \n' + JsonOutput.prettyPrint(JsonOutput.toJson(responseList)))
assertThat(responseList.Good.A.count).isEqualTo("29")
也尝试使用 [0],但它也没有出现错误java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
assertThat(responseList.Good[0].A).isEqualTo("29")
解决方案
尝试使用普通的 Groovy 断言。将您的断言行更改为以下内容:
assert responseList.Good.A.count == 29