Are there any alternatives to XmlUnit?

本小妞迷上赌 提交于 2019-11-30 11:29:28
greuze

I have a similar problem, in my case, I had several tags with the same name, but different attributes (the order didn't matter), but XmlUnit always checked first with first, second with second... that could be swapped. My question was:

Comparing similar xml files with XmlUnit with unordered tags (same tag name with different attributes)

I found a solution here:

http://www.infoq.com/articles/xml-unit-test

In my case, it was solved just overriding the element qualifier:

    Diff diff = new Diff(controlXml, responseXml);
    diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
unludo

I found out that setting the following option resolved the problem of inaccurate (un)similarity:

XMLUnit.setIgnoreWhitespace(true);

I agree with Jim's comment. Most of issues I faced with XmlUnit was due to incorrect initialization.

However, you could always take a look at the XMLUnit source code and substitute Diff handler with your own if you feel like implementation is not doing what you need. The code is quite easy to understand and you will be able to fully control behavior without much effort needed to implement your own diff engine.

anonymous

It is better to sort XML, before comparing it with xmlunit, instead of using xmlunit sorting write your own, it would be much easier than configuring xmlunit for your needs

have you tried XUnit?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!