我尽力了
@Test
public void testGetSingleUser() {
given().expect().
statusCode(200).contentType(ContentType.JSON).
body("_testingString", equalTo("got it")).when().
get("http://localhost:8080/getIt");
}
但总是收到此错误消息
Assert错误:JSON路径_testingString不匹配。
预期:“得到了”得到了:[收到]
如何忽略“”和[]问题谢谢
2条答案
按热度按时间0dxa2lsx1#
**注意:**这是未经测试的代码片段,但在查看错误跟踪时,它可能会对您有所帮助。
尝试
代替
332nm8kg2#
当您收到一个错误消息,内容如下:
JSON路径总数不匹配。应为:2000年实际数:〈[2000年]〉
这意味着您的结果(Actual:)将进入数组。
因此,您应该使用rest-assured-command(例如,hasItem)来验证“数组内部”的值。
下面的代码说明了这种情况的解决方案: