New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide unordered collection diff support #111
Comments
XMLUnit is not aware of XML-Schema when it calculates differences, although this would be a great enhancement see also #88 . If element order is not significant for you, you can tell the difference engine by providing a
should work. |
Unfortunately it doesn't work. xmlunit/xmlunit#111 (comment)
@bodewig Thanks for the quick feedback! Global switch for unordered collection will work for my immediate needs but the suggestion didn't work for me. It might be a fault on my end when applying your suggestion as I'm almost new to XMLUnit. This is what I tried with your suggestion: https://github.com/izeye/samples-java-branches/blob/master/src/test/java/learningtest/org/xmlunit/diff/DiffTests.java#L88-L105 |
Ah, in your case XMLUnit simply doesn't compare the elements you probably want it to compare. The In order to make your test pass you need to help XMLUnit matching the correct .withNodeMatcher(new DefaultNodeMatcher(conditionalBuilder()
.whenElementIsNamed("person").thenUse(byXPath("./id", byNameAndText))
.elseUse(byNameAndText)
.build()) should work, I haven't tried it. (just assume there was a static import on See https://github.com/xmlunit/user-guide/wiki/SelectingNodes for all the details. |
@bodewig Thanks again for the quick response! I think I understand your first advice now thanks to your second advice and I updated my tests based on it: https://github.com/izeye/samples-java-branches/blob/master/src/test/java/learningtest/org/xmlunit/diff/DiffTests.java#L89-L123 Both work like a charm 👍 I'm happy with the current solution for now but I'd like to keep this issue open for a possible enhancement based on XML schema for ordered and unordered mixed documents diff. |
Glad it worked. Keeping the issue open as an enhancement request is fine with me, I've labeled it accordingly. |
If the strings were like this : String xml1 = How would you use multiple selectors to make the comparison? |
@michailangelo I think this is a different question, so please open a new issue. |
I thought this is relevant to the discussion before but I opened a new issue anyway :) |
The current implementation of
Diff
looks to have an assumption that collection is ordered and doesn't look there's any switch to the assumption so that unordered collections can be handled.It would be nice to provide unordered collection diff based on XML schema.
This is a test to illustrate what I'm trying to suggest: https://github.com/izeye/samples-java-branches/blob/master/src/test/java/learningtest/org/xmlunit/diff/DiffTests.java#L62-L82
The text was updated successfully, but these errors were encountered: