java - 试图恢复预期和实际匹配的 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
解决方案
提供的 JSON 对象24
在 key 下具有数字"id"
。它不是 JSON 字符串,而是"24"
.
你试过equalTo(24)
吗?与数字文字一样,而不是字符串文字。
推荐阅读
- python - 将网页抓取代码扩展到多个页面
- javascript - 有没有办法让复选框在切换到另一个页面后保持相同的状态?
- javascript - 验证值是否在 Google 表格中
- amazon-web-services - 如何直接连接和访问 AWS 胶水中的本地 SFTP 服务器?
- c - C 从标准输入读取行
- linux - 如何将变量传递给shell上的ssh命令
- huawei-mobile-services - 添加Pass包时出现问题
- python - 在 python openurl 方法中 read().decode('utf-8') 之后,HttpResponseObject 是否会发生变化?
- javascript - 根据表格宽度换行列文本 antd
- php - 在共享主机上增加 PHP 网站中的会话超时