【问题标题】:I'm not able to assert body json properties我无法断言 body json 属性
【发布时间】:2016-04-06 14:41:47
【问题描述】:

我正在使用 Rest Assured 来测试我的 API。我的客户端端点 (/client) 返回如下 JSON:

{
  "id":1,
  "nombre":"Juan Loquesea",
  "email":"juan@gmail.com",
  "idProvincia":7,
  "fechaRegistro":"06/04/2016 10:00:00"
}

这是我的测试代码:

public void test() {
    get("/client").then().assertThat()
           .statusCode(200)
           .body("id", equalTo(1));
}

但我收到此错误:

java.lang.IllegalArgumentException: Invalid JSON expression:
Script1.groovy: 1: expecting EOF, found ':' @ line 1, column 31.
                            http://172.'20'.'20'.'20:8080'.id
                                 ^

发生了什么?

【问题讨论】:

  • 看起来您没有收到预期的 json

标签: java json rest-assured


【解决方案1】:

解决了!我的测试类中有这段代码:

@BeforeClass
public static void init() {
  RestAssured.rootPath = "http:172.20.20.20:8080"
}

我已经删除了它,它现在可以工作了。

【讨论】:

    猜你喜欢
    • 2017-12-29
    • 2018-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-21
    • 2021-12-16
    • 1970-01-01
    • 2016-06-30
    相关资源
    最近更新 更多