Comparing XML Elements in JUnit

Cannot execute the JUnit class, which is trying to compare XML input with XML output.

TestCase.assertEquals(msg, expected, actual); 

Is there a way to compare XML i / p and o / p with JUnit?

+6
source share
1 answer

You can look at XMLUnit . This allows you to compare two XML documents. From the docs:

XMLUnit allows you to approve JUnit style statements regarding the content and structure of XML. This is an open source project organized at http://xmlunit.sourceforge.net/ , which has grown because of the need to test the system that generated and received custom XML messages. The problem we are faced with is how to verify that the system generated the correct message from a known set of inputs. Obviously, we could use DTD or schemas to check the output of the message, but this approach will not allow us to distinguish between valid XML with the correct content (for example, an element string) and valid XML with the wrong content (for example, a baz element). What we really wanted was the assertXMLEqual () method, so we could compare the message that we expected to generate with the message that the system actually generated.

+6
source

Source: https://habr.com/ru/post/900912/


All Articles