【问题标题】:What's the most efficient way of making hamcrest assertions for a JSON object with many keys?为具有许多键的 JSON 对象进行 hamcrest 断言的最有效方法是什么?
【发布时间】:2021-02-15 10:59:14
【问题描述】:

我正在对 RestAssured 的 ValidateableResponse 类(即 xxxyyzz.then().body(matchers))进行断言。在这里,我在这个响应中有很多 JSON 键值对,我可以对每个 JSON 键使用 .then().body("path",hasKey(operator)) 方法,但是,这很烦人。还有其他更有效的方法来验证多个 JSON 密钥吗?

最好的,

【问题讨论】:

    标签: json rest-assured matcher hamcrest


    【解决方案1】:

    如果您需要验证某些实体的列表/数组,您可以执行以下操作:

       response
          .getBody()
          .jsonPath()
          .getList("data.owner_type")
          .forEach(ownerType -> hasKey("public"));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-26
      • 1970-01-01
      • 2016-11-09
      • 1970-01-01
      • 2012-09-14
      • 2010-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多