XMLUnit 是否有一个断言来忽略空格
我想在测试中比较两个 xml 字符串,但由于空格,测试一直失败。
@Test
public void testForEquality() throws Exception {
String myControlXML = "<msg><uuid>0x00435A8C</uuid></msg>";
String myTestXML = "<msg><uuid>0x00435A8C</uuid> </msg>";
assertXMLEqual(myControlXML, myTestXML);
Diff diff = new Diff(myControlXML, myTestXML);
assertTrue(diff.similar());
}
I want to compare two xml strings in a test, but the test keeps failing due to whitespace.
@Test
public void testForEquality() throws Exception {
String myControlXML = "<msg><uuid>0x00435A8C</uuid></msg>";
String myTestXML = "<msg><uuid>0x00435A8C</uuid> </msg>";
assertXMLEqual(myControlXML, myTestXML);
Diff diff = new Diff(myControlXML, myTestXML);
assertTrue(diff.similar());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,XMLUnit 可以忽略空格。有关详细信息,请参阅 API 文档。您可以通过设置启用它:
Yes, XMLUnit can ignore whitespaces. See API documentation for details. You can enable it by setting:
XMLUnit 2.x 中的 API 已发生更改。
现在,对于单元测试,您可以使用 hamcrest 匹配器忽略空格,如下所示:
或者直接使用构建器 API:
The API has changed with XMLUnit 2.x.
Now, for unit tests, you can ignore whitespace with a hamcrest matcher like so:
Or alternatively, with the builder API directly: