-
Notifications
You must be signed in to change notification settings - Fork 8
ComparisonFormatter
brabenetz edited this page Jul 18, 2015
·
4 revisions
| XMLUnit 2.x has not been released, yet. This documentation may change until the final release of XMLUnit. |
|---|
The ComparisonFormatter will format the differences between control and test xml for human readable as one String.
Normally the default formatter will be used: org.xmlunit.diff.DefaultComparisonFormatter
But you can also implement your own formatter. There are two methods to implement:
String getDescription(Comparison difference); // [1]
String getDetails(Detail details, ComparisonType type, boolean formatXml); // [2]-
getDescription(Comparison):
should return a short human readable description what the differences are.
Example: Return the String"Expected number of attributes '1' but was '2' - comparing <a...> at /a[1] to <a...> at /a[1]" -
getDetails(Detail, ComparisonType, boolean):
should return the comparison details from the effected Test- or Control-Node. See getDetails(Detail, ComparisonType, boolean)
The default implementation DefaultComparisonFormatter returns the XML snippet which contains the differences.
This XML snippets are used by the org.xmlunit.matchers.CompareMatcher to create
a org.junit.ComparisonFailure which can show the differences in your IDE as a nice Diff-View.
- The
DetailArgument contains either the details of the Control-Node or the Test-Node. - Depending on the
ComparisonTypeof the differences the target-node, his parent or the whole document should be returned as XML-Snippet. - The boolean
formatXmltells if the resulting xml should be formatted or not.
For Example: if the input source was wrapped with a WhitespaceStrippedSource the resulting XML can and should be formatted to be human readable. But if the source was not wrapped by a content modification source, the formatting could remove/hide the real differences between test and control node.
- Overview
- General Concepts
- Comparing XML
- Validating XML
- Utilities
- Migrating from XMLUnit 1.x to 2.x
- Known Issues