Questions tagged [xmlunit]

XMLUnit is an open source project which enables JUnit-style assertions to be made about the content and structure of XML.

XMLUnit extends and to enable unit testing of XML.

It compares a control XML document to a test document or the result of a transformation, validates documents, and compares the results of expressions.

XMLUnit for Java

XMLUnit for Java provides two JUnit extension classes, XMLAssert and XMLTestCase, and a set of supporting classes (e.g. Diff, DetailedDiff,Transform,SimpleXpathEngine,Validator,NodeTest) that allow assertions to be made about:

  • The differences between two pieces of XML
  • The outcome of transforming a piece of XML using XSLT
  • The evaluation of an XPath expression on a piece of XML
  • The validity of a piece of XML
  • Individual nodes in a piece of XML that are exposed by DOM Traversal

XMLUnit for Java can also treat HTML content (even badly-formed HTML) as valid XML to allow these assertions to be made about the content of web pages too.

XMLUnit is available for and .

184 questions
5
votes
3 answers

How can I compare two similar XML files in XMLUnit

I want to use XMLUnit to compare two similar XML files. Basically every thing is same, File1 is a copy of File2 , but in File2 I have changed the order of some elements in one node. I am trying to run a test where it compares these files and…
Ahmed
  • 51
  • 1
  • 1
  • 2
4
votes
1 answer

Ignore empty tags in xmlunit

Is there any way to completely ignore an empty tag in XMLUnit so that it is not taken into account for comparison? Ex: data1 data2 and data1 data2 should not return any difference. Is there any…
4
votes
4 answers

XMLUnit Compare Xml comparing wrong Nodes

I am having an issue when you have the parent node in different order. For example: Sample XML1 FirstParent AAA BBB
Charles
  • 41
  • 2
4
votes
1 answer

XMLUnit Compare Xml Ignoring Sequence

I need to compare 2 XML's for which I am using my custom Difference Listener which is ignoring Child Node Sequence and Attribute List Sequence: if (difference.getId() == DifferenceConstants.CHILD_NODELIST_SEQUENCE_ID || difference.getId() ==…
Rahul Dabas
  • 726
  • 2
  • 15
  • 27
4
votes
1 answer

Compare two JDOM2 documents for equality

I have an application that generates XML documents using the JDOM2 library. In my unit/integration tests, I would need to compare the generated documents against handmade sample documents for equality. With standard org.w3c.dom.Document objects, I…
Dušan Rychnovský
  • 11,699
  • 8
  • 41
  • 65
4
votes
1 answer

Find missing elements using XMLUnit

I have the following testXML test bee While the templateXML looks like this I want XMLUnit to return the missing elements, in this case 'c' and…
SDS
  • 57
  • 2
  • 8
3
votes
1 answer

XML Unit - Using custom element selectors on different xml elements

I'm having a problem comparing various elements in my xml document with XMLUnit (2.2.1). In my document there are several xml elements and I want to know, whether they differ from each other. However, I don't want to compare all xml elements the…
fwshngtn
  • 35
  • 1
  • 7
3
votes
1 answer

Groovy : Compare SOAP Response with XML file

I want to compare in groovy code my Soap Response with xml file ignoring order : Here is my code : import org.custommonkey.xmlunit.Stuff import org.xmlunit.Stuff //ExpectedString is my xml converted to text, same for ResponseString Diff diff =…
Hamza Amami
  • 94
  • 4
  • 21
3
votes
2 answers

How to remove an attribute from testing in XMLUnit in Java?

I wanted to skip two attributes from my acceptance test.So I added following part to remove that two attributes.This is given me a error: junit.framework.AssertionFailedError: org.custommonkey.xmlunit.Diff [different] Expected number of element…
user2490093
  • 69
  • 10
3
votes
3 answers

JUnit Test if XML Document is sorted on arbitrary column

Given an xml document like 2 1 8 5 2 8 2 8 6 Is there an easy way to assert that…
sal
  • 23,373
  • 15
  • 66
  • 85
3
votes
3 answers

Compare two documents where both parent elements and child elements are ordered diffently

I'm trying to unit test some methods that produce xml. I have an expected xml string and the result string and after googling and searching stack overflow, I found XMLUnit. However it doesn't seem to handle one particular case where repeating…
Munick
  • 451
  • 3
  • 16
3
votes
1 answer

Unexpected difference found when comparing elements with empty elements in xmlUnit

Comparing these two snippets of XML: testXml: actualXml: notEmpty using: Diff diff = new Diff(testXml, actualXml); Detailed detailedDiff = new…
Olle Söderström
  • 690
  • 1
  • 7
  • 15
2
votes
1 answer

Ignore Case with XMLUnit

Is there a way to get XML Unit to ignore case when comparing two XMl documents? Both the tags and their values... is the same to me as ? XMLUnit give me the following Difference: Expected attribute value 'FALSE' but was 'false' I tried simply using…
kralco626
  • 8,456
  • 38
  • 112
  • 169
2
votes
0 answers

XmlUnit - how to ignore namespace prefix and compare 2 xml files?

I have two xml files. First contains namespace prefix and the second one doesn't. So when I assert them I want to ignore these prefixes and check for equality. @Test public void test1(){ String control = "
fcka
  • 21
  • 2
1
2
3
12 13