I am looking for a good java library to compare xml files in unit tests. Currenly we are using a simple string compare, but this requires that the xml file is printed the same way (currenly on 1 line).
I have found the following on the net: http://xmlunit.sourceforge.net/. But i looks old (latest version from September 2009). Does somebody knows a more recent library or is this still the one to use?
Thanks
JUnit is an open-source regression testing framework that is used mainly by expert software developers to execute unit testing, speed up programming, and improve the quality of code in Java.
XMLUnit 2. x is a powerful library that helps us test and verify XML content, and comes in particularly handy when we know exactly what that XML should contain.
Java testing provides thorough and functioning test cases that can test every aspect of your application. A JUnit test case is exactly what it sounds like: a test scenario measuring functionality across a set of actions or conditions to verify the expected result. JUnit is a simple framework to write repeatable tests.
xml-matchers is what you're looking for. The library seems to be actively supported:
assertThat(the(xml), isEquivalentTo(the(xml2)));
Also, try jcabi-matchers:
assertThat(XhtmlMatchers.the(xml), XhtmlMatchers.hasXPath("/html/body"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With