我正在用RestAssured编写测试用例,以便使用spring测试rest mvc服务。
rest响应是
{
"links": [
{
"rel": "self",
"href": "http://www.localhost.com:8080/v1/communities?offset=0&limit=10"
},
{
"rel": "next",
"href": "http://www.localhost.com:8080/v1/communities?offset=10&limit=10"
}
],
"content": [
{
.....我的测试用例是
when().
get("/communities").
then().
root("links").
body("href", new ResponseAwareMatcher() {
public Matcher<? extends Object> matcher(ResponseBody response) {
return equalTo(new String[] {"http://www.localhost.com:8080/v1/communities?offset=0&limit=10", "http://www.localhost.com:8080/v1/communities?offset=10&limit=10"});
}
});测试用例失败时出错
java.lang.AssertionError: 1 expectation failed.
JSON path links.href doesn't match.
Expected: ["http://www.localhost.com:8080/v1/communities?offset=0&limit=10", "http://www.localhost.com:8080/v1/communities?offset=10&limit=10"]
Actual: [http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10]我甚至试过
equalTo("[http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10");它将错误地输出为
java.lang.AssertionError: 1 expectation failed.
JSON path links.href doesn't match.
Expected: [http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10]]
Actual: [http://www.localhost.com:8080/v1/communities?offset=0&limit=10, http://www.localhost.com:8080/v1/communities?offset=10&limit=10]我使用的是放心3.0.1。谢谢你提前帮忙。
发布于 2016-10-06 18:09:13
尝尝这个
assertEquals("http://www.localhost.com:8080/v1/communities?offset=0&limit=10", given().when().get("/communities").body().jsonPath().get("links[0].href"));https://stackoverflow.com/questions/39902246
复制相似问题