org.assertj.core.api.Assertions doesNotContain 数组错误
org.assertj.core.api.Assertions doesNotContain array error
我想使用 doesNotContain 来确保响应不包含该字符串。但遇到错误。
应该使用的正确参数是什么?
测试脚本:
import static org.assertj.core.api.Assertions.*
def testjson= new JsonSlurper().parseText(new String(response.responseText))
println('response text: \n' + JsonOutput.prettyPrint(JsonOutput.toJson(testjson)))
assert (testjson.testLines.lineId.contains("test123"))
assert (testjson.testLines.lineId.doesNotContain("test456"))
错误
Reason:
groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.doesNotContain() is applicable for argument types: (java.lang.String) values: [test456]
示例响应:
{
"testId": "default",
"createdDate": "2020-05-11T01:51:32.986Z",
"lastUpdatedDate": "2020-05-11T01:51:32.986Z",
"testLines": [
{
"lineId": "test123",
"itemId": "test/test123"
},
{
"lineId": "test999",
"itemId": "test/test999"
}
]
}
编译器抱怨 doesNotContain()
方法需要一些其他输入。我不知道那个方法,但如果 contains()
方法有效,你可以使用“!”来否定那个方法的结果。在逻辑语句前面:
assert (!testjson.testLines.lineId.contains("test123"))
我想使用 doesNotContain 来确保响应不包含该字符串。但遇到错误。
应该使用的正确参数是什么?
测试脚本:
import static org.assertj.core.api.Assertions.*
def testjson= new JsonSlurper().parseText(new String(response.responseText))
println('response text: \n' + JsonOutput.prettyPrint(JsonOutput.toJson(testjson)))
assert (testjson.testLines.lineId.contains("test123"))
assert (testjson.testLines.lineId.doesNotContain("test456"))
错误
Reason:
groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.doesNotContain() is applicable for argument types: (java.lang.String) values: [test456]
示例响应:
{
"testId": "default",
"createdDate": "2020-05-11T01:51:32.986Z",
"lastUpdatedDate": "2020-05-11T01:51:32.986Z",
"testLines": [
{
"lineId": "test123",
"itemId": "test/test123"
},
{
"lineId": "test999",
"itemId": "test/test999"
}
]
}
编译器抱怨 doesNotContain()
方法需要一些其他输入。我不知道那个方法,但如果 contains()
方法有效,你可以使用“!”来否定那个方法的结果。在逻辑语句前面:
assert (!testjson.testLines.lineId.contains("test123"))