【发布时间】:2016-09-13 18:28:26
【问题描述】:
我正在与:
- Spring MVC 测试
- 哈姆克雷斯特
对于集合中的一个项目,例如:
<collection>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="persona">
<id>087</id>
<nombre>Leonardo</nombre>
<apellido>Jordan</apellido>
<fecha>1981-07-05</fecha>
</item>
....
以下作品:
.andExpect(xpath("collection/item[1]").exists())
.andExpect(xpath("collection/item[1]/*").nodeCount(is(4)))
.andExpect(xpath("collection/item[1]/id").exists())
.andExpect(xpath("collection/item[1]/id").string(is("087")))
.andExpect(xpath("collection/item[1]/id").string(is(personasArray[0].getId())))
.andExpect(xpath("collection/item[1]/nombre").exists())
.andExpect(xpath("collection/item[1]/nombre").string(is("Leonardo")))
.andExpect(xpath("collection/item[1]/nombre").string(is(personasArray[0].getNombre())))
.andExpect(xpath("collection/item[1]/apellido").exists())
.andExpect(xpath("collection/item[1]/apellido").string(is("Jordan")))
.andExpect(xpath("collection/item[1]/apellido").string(is(personasArray[0].getApellido())))
我想知道是否可以直接比较对象而不是每个字段,考虑一个具有 15 到 45 个字段的实体。
我需要这样的东西:
.andExpect(xpath("collection/item[1]/*").how(is(personasArray[0])))
参见how 部分,它代表了正确的使用方法。
对path 的字符串内容同样考虑。
【问题讨论】:
标签: xml xpath spring-test-mvc