Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good java library to compare xml files for unit testing? [closed]

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

like image 984
cremersstijn Avatar asked Sep 10 '12 12:09

cremersstijn


People also ask

Which is a Java library for unit testing?

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.

What is XMLUnit?

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.

What does .test do in Java?

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.


1 Answers

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"))
like image 200
yegor256 Avatar answered Sep 30 '22 18:09

yegor256