如何在rest assured中验证Json响应字段的数据类型

回首 测试交流1 127字数 502阅读模式
摘要我们如何验证上述字段(如“Json”)的Json数据类型;价格&引用;ck“&引用;名称&引用;“已启用”;和“;标签“;在放心测试中。 { "...

我们如何验证上述字段(如“Json”)的Json数据类型;价格&引用;ck“&引用;名称&引用;“已启用”;和“;标签“;在放心测试中。

    {
"odd": {
"price": 200,
"ck": 12.2,
"name": "test this",
"enabled": true,
"tags": null
}
}

是否有任何方法或断言库可以提供rest-assured测试示例中提到的数据类型验证,其中我们可以只验证以下示例中提到的数据类型,而不是断言给定键的实际值。文章源自玩技e族-https://www.playezu.com/190314.html

ValidatableResponse response =
given().
    spec(requestSpec).
    headers("authkey", "abcdxxxxxxxxxyz").
    pathParam("uid", oddUid).
when().
    get("/orders" + "/{uid}").
then().
    assertThat().
    statusCode(200).
    body(
           "odd.price",  isNumber(),
           "odd.name", isString(),
           "enabled", isboolean()
           "tags", isNull()
         );

catia软件功能测试文章源自玩技e族-https://www.playezu.com/190314.html 文章源自玩技e族-https://www.playezu.com/190314.html

玩技站长微信
添加好友自动发送入群邀请
weinxin
rainbow-shownow
玩技官方公众号
官方微信公众号
weinxin
PLAYEZU
 
  • 版权提示:本站仅供存储任何法律责任由作者承担▷诈骗举报◁▷新闻不符◁▷我要投稿◁
    风险通知:非原创文章均为网络投稿真实性无法判断,侵权联系2523030730
    免责声明:内容来自用户上传发布或新闻客户端自媒体,切勿!切勿!切勿!添加联系方式以免受骗。
  • 原创转载:https://www.playezu.com/190314.html
    转载说明: 点我前往阅读>>>
    • cheparsky
      cheparsky 9

      如果我们想验证我们在 .正文() 方法,然后我们可以使用Rest Assured内置匹配器 匹配器 类别:
      import static org.hamcrest.匹配器.isA;
      import static org.hamcrest.匹配器.nullValue;

      given().
      spec(requestSpec).
      headers("authkey", "abcdxxxxxxxxxyz").
      pathParam("uid", oddUid).
      when().
      get("/orders" + "/{uid}").
      then().
      body("odd.price", isA(Integer.class)).
      body("odd.name", isA(String.class)).
      body("enabled", isA(Boolean.class)).
      body("tags", nullValue()).

      或者我们可以使用一些断言库,例如AssertJ:
      import static org.assertj.core.api.Assertions.assertThat;

      JsonPath response = given().
      spec(requestSpec).
      headers("authkey", "abcdxxxxxxxxxyz").
      pathParam("uid", oddUid).
      when().
      get("/orders" + "/{uid}").
      then().
      extract().jsonPath();

      assertThat(jsonPath.get("odd.price") instanceof Integer).isTrue();

    匿名

    发表评论

    匿名网友
    确定