我的示例Web服务正在返回以下XML。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<errorResponse>
<errorCode>Wrong ID</errorCode>
<errorId>2</errorId>
</errorResponse>
通过了以下测试。
response.then().body("errorResponse.errorId", Matchers.is("2"));
response.then().body("errorResponse.errorCode", Matchers.is("Wrong ID"));
response.then().body("errorResponse1.errorCode", Matchers.is("Wrong ID"));
response.then().body("errorResponse2.errorCode", Matchers.is("Wrong ID"));
我知道前两项测试很好,但我没有得到的是为什么后两项通过了?
答案 0 :(得分:1)
确保放心使用其 xml-path 库评估您的hamcrest匹配器,并且该库包含XMLAssertion类,该类会进行实际检查。
在此文件的第60行,您可以看到它删除了第一个点之前的搜索关键字部分,因为它可以识别出我们正在从根节点进行评估。
输入您的密钥:
"errorResponse3.errorCode"
成为
".errorCode"
因此,最初的路径看起来并不重要,它假定它是根节点的名称,并且无论如何都将其丢弃。