2
我决定使用REST-Assured来测试REST服务。结果(主要)是JSON和XML文档。为了检查JSON,我发现JSONassert非常有帮助。将REST-Assured的ifValidationFails与JSONAssert一起使用
我不想比较身体的部位,但是完整身体的一个反应。所以,examples at REST-Assured's documentation不是很有帮助,因为它们提取响应主体的一部分。
目前,我提取的身体和事后比较正文:
public void assertGet(String restURL, String fileName) throws Exception {
String expectedStr = readFromClasspath(fileName);
final String receivedStr = given()
.log()
.ifValidationFails()()
.accept(getAccept(fileName))
.get(callURL(restURL))
.then()
.log()
.ifValidationFails()
.statusCode(200)
.extract()
.response()
.getBody()
.asString();
if (isXml(fileName)) {
org.hamcrest.MatcherAssert.assertThat(receivedStr, CompareMatcher.isIdenticalTo(expectedStr).ignoreWhitespace());
} else {
JSONAssert.assertEquals(
expectedStr,
receivedStr,
true);
}
}
的问题是,ifValidationFails()
没有任何意义,因为asString()
总是成功的。
现在我不知道如何可以包括JSONAssert.assertEquals
和Hamcrest的assertThat
到的方法REST保证的对验证失败启用日志记录。
完整的数据来源于Eclipse Winery's repository。