我在加特林有一个场景,我想检查响应正文值是否映射到错误字符串。响应为400:
{"error": "ERROR_1"}
检查失败,出现编译错误:
http("Some Request")
.put("/endpoint")
.asJson
.check(jsonPath("$.error") == "ERROR_1")
.check(status.is(400))
也尝试将错误保存为变量
.check(jsonPath("$.error").saveAs("error"))
.check("${error}" == "ERROR_1")
并且意识到.check("${error}".is("ERROR_1"))
也不起作用,因为。仅适用于int。加特林文档也没有过多地解释表达式https://gatling.io/docs/current/http/http_check#validating
有什么想法吗?
您的仅适用于int的声明不正确-这就是您应该构造此检查的方式。
这是一个通过合格检查的工作示例
def test : ScenarioBuilder = scenario("test")
.exec(
http("test call")
.post("http://httpbin.org/anything")
.body(StringBody("""{"error": "ERROR_1"}"""))
.check(jsonPath("$..error").is("ERROR_1"))
)
您不能使用==
,因为检定检查需要一个或多个HttpChecks,并且==
返回一个布尔值。