首页 > 解决方案 > 试图恢复预期和实际匹配的 API 响应的 ID?

问题描述

我一直在测试我在测试中寻找 ID 24 的 api,而我的实际和预期是相同的

    @Test
public void test_get_userid() {

    given().
            when().
            get("http://bpdts-test-app-v2.herokuapp.com/user/24").
            then().
            assertThat().
            statusCode(200).
            and().
            contentType(ContentType.JSON).
            and().
            body("id", equalTo("24"));
}

java.lang.AssertionError: 1 expectation failed.
JSON path id doesn't match.
Expected: 24
  Actual: 24

标签: javatestngrest-assured

解决方案


提供的 JSON 对象24在 key 下具有数字"id"。它不是 JSON 字符串,而是"24".

你试过equalTo(24)吗?与数字文字一样,而不是字符串文字。


推荐阅读