Reputation: 3207
Hi I'm trying to use XML Units RecursiveElementNameAndTextQualifier , But my below test is failing. When I interchange the value of foo3 and foo2 in below test xml file , the test is passed with true (for diff.similar()) . Not sure what the issue is.RecursiveElementNameAndTextQualifier is only going to specific depth ?
Contorl :
<table>
<tr>
<td>
<a>foo</a>
<a>foo1</a>
</td>
<td>
<a>foo2</a>
<a>foo3</a>
</td>
</tr>
<tr>
<td>
<a>bar</a>
</td>
</tr>
</table>
**Test:**
<table>
<tr>
<td>
<a>bar</a>
</td>
</tr>
<tr>
<td>
<a>foo3</a>
<a>foo2</a>
</td>
<td>
<a>foo1</a>
<a>foo</a>
</td>
</tr>
</table>
DetailedDiff detDiff = new DetailedDiff(diff);
diff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
XMLUnit.setNormalizeWhitespace(true);
System.out.println("Similar? " + diff.similar());
Upvotes: 0
Views: 580
Reputation:
Things seem to work better when you swap the foo2 and foo3 lines, but only by accident. If you tell XMLUnit to not randomly match elements it shouldn't match with
XMLUnit.setCompareUnmatched(false);
you will see a completely different picture.
[different] Expected presence of child node 'tr' but was 'null' - comparing <tr...> at /table[1]/tr[1] to at null
[not identical] Expected sequence of child nodes '3' but was '1' - comparing <tr...> at /table[1]/tr[2] to <tr...> at /table[1]/tr[1]
[different] Expected presence of child node 'null' but was 'tr' - comparing at null to <tr...> at /table[1]/tr[2]
RecursiveElement...
picks the tr
s with the nested bar texts but doesn't consider the other two tr
s comparable at all. XMLUnit just picks them because there are no other matches (and picking elements in order is the default fallback unless you use the flag above.
RecursiveElementNameAndTextQualifier
only works if the child elements appear in the exact same order - which is not the case for the children of the tr
s and not even for the children of the td
s.
Upvotes: 1