JUnit class which tries to compare the XML input with the XML output fails.
TestCase.assertEquals(msg, expected, actual);
Is there any way to compare XML i/p & o/p from JUnit?
You could look at XMLUnit. This allows you to compare two XML documents. From the docs:
XMLUnit enables JUnit-style assertions to be made about the content and structure of XML. It is an open source project hosted at http://xmlunit.sourceforge.net/ that grew out of a need to test a system that generated and received custom XML messages. The problem that we faced was how to verify that the system generated the correct message from a known set of inputs. Obviously we could use a DTD or a schema to validate the message output, but this approach wouldn't allow us to distinguish between valid XML with correct content (e.g. element bar) and valid XML with incorrect content (e.g. element baz). What we really wanted was an assertXMLEqual() method, so we could compare the message that we expected the system to generate and the message that the system actually generated.
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