【问题标题】:RestAssured, JSON: verify absence of a value in a fieldRestAssured,JSON:验证字段中是否缺少值
【发布时间】:2019-12-16 11:40:10
【问题描述】:

我有以下示例 URI:

localhost/users

当我向它发送请求时,这个 JSON 作为响应:

[
  {
    "id": 1,
    "name": "Joe"
,
  {
    "id": 3,
    "name": "Ben"
,
  {
    "id": 4,
    "name": "Jim"
    }
  }
]

如何使用 RestAssured 进行验证,例如没有 id = 2 的用户?

会不会是这种半伪的东西:

 given().spec(requestSpecification)
                .when().get("/users")
                .and().body("id==2", ????);

任何建议/指导将不胜感激,谢谢。

【问题讨论】:

    标签: java json rest-assured


    【解决方案1】:

    试试这个:

    given().spec(requestSpecification)
                    .when().get("/users")
                    .and().body("id", is(not(equalTo(2))));
    

    使用放心文档部分Use the response to verify other parts of the response 提供了更多详细信息。

    is(not(Matcher))hamcrest提供

    【讨论】:

    • 不是吗?当我试图在那里写它时,它只是不在变体列表中......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多