我在我的 JUnit 测试中将保存的示例 xml 与实时编组的 xml 进行比较。验证 xml 中是否存在键值对。
我正在专门使用XmlUnit 2.1.0
我的xml如下:
<entries>
<entry>
<key>delete</key>
<value>ENABLED</value>
</entry>
<entry>
<key>view</key>
<value>DISABLED</value>
</entry>
<entry>
<key>create</key>
<value>DISABLED</value>
</entry>
</entries>
条目的顺序可能会有所不同。我不确定如何让它正确验证,因为即使它只是订单更改,它也会将不同的键值视为 xml 中的差异。
我断言与 JUnit 中的以下断言相似:
assertThat(marshalledXml, isSimilarTo(Input.fromFile("path/to/example.xml").ignoreWhitespace().ignoreComments());
我怀疑我可能需要使用 XPath 匹配器或带有 ElementSelector 的 DefaultNodeMatchers。