assert - org.assertj.core.api.Assertions doesNotContain 数组错误
问题描述
我想使用 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"))
推荐阅读
- javascript - 如何跨应用更新保存用户数据?
- shell - 控制du ordering
- c# - 如何绕过 RestSharp“需要一个强名称的程序集”
- javascript - JavaScript:当数组为空时解构对象数组时出错
- extjs - ExtJs:为什么 numberfield 在显示数据时会自动将 null 转换为 0
- php - 为什么 PHP 会在输入时删除文件的内容?
- sql - 将字符串转换为时间戳并在 BigQuery SQL 中使用 timestamp_diff
- ansible - 如何在 ansible 查找模块中使用模式、年龄、年龄标记选项
- ios - iOS 12.4.1 发布在苹果商店拒绝 ipad 设备时崩溃
- visual-studio-2012 - VSCode 中的权限被拒绝(公钥)