我使用JSON料器JSON输出由Web服务如下比较比较Web服务JSON响应,加特林: - 使用jsonFileFeeder
val jsonFileFeeder = jsonFile("test_data.json")
val strategy = (value: Option[String], session: Session) => value.map { jsonFileFeeder =>
val result = JSONCompare.compareJSON("expectedStr", "actualStr", JSONCompareMode.STRICT)
if (result.failed) Failure(result.getMessage)
else Success(value)
}.getOrElse(Failure("Missing body"))
val login = exec(http("Login")
.get("/login"))
.pause(1)
.feed(feeder)
.exec(http("authorization")
.post("/auth")
.headers(headers_10)
.queryParam("""email""", "${email}")
.queryParam("""password""", "${password}")
.check(status.is(200))
.check(bodyString.matchWith(strategy)))
.pause(1)
但它抛出错误
value matchWith is not a member of io.gatling.core.check.DefaultFindChe
ckBuilder[io.gatling.http.check.HttpCheck,io.gatling.http.response.Response,String,String]
15:10:01.963 [ERROR] i.g.a.ZincCompiler$ - .check(bodyString.matchWith(jsonFileFeeder)))
s\lib\Login.scala:18: not found: value JSONCompare
15:10:05.224 [ERROR] i.g.a.ZincCompiler$ - val result = JSONCompare.compareJSON(jsonFileFeeder, j
sonFileFeeder, JSONCompareMode.STRICT)
^
15:10:05.631 [ERROR] i.g.a.ZincCompiler$ - two errors found
Compilation failed
这个错误似乎表明'matchWith'函数和'JSONCompare'对象不存在 - 这是真的,在Gatling中没有这样的代码(我猜'JSONCompare'来自JSONAssert,不确定'matchWith' )。虽然可能修复此代码,但是您是否考虑过使用jsonPath,我怀疑这会证明更容易,更灵活? – 2014-09-10 13:25:04
@James_pic: - 请问您可以添加一些snipet代码,我如何使用JSONFeeder来比较Web服务JSON响应? – 2014-09-10 13:34:06
JSON响应有多大?另外,重要的是它完全匹配,还是仅仅检查返回的JSON的一个或两个元素会令人满意? – 2014-09-10 13:45:21