Skip to content
Stefan Bodewig edited this page Nov 24, 2015 · 9 revisions

Comparison and Difference

(DOM)DifferenceEngine

The DifferenceEngine is part of the low level API that offers access to all features provided by the library.

Selecting Nodes to Compare With Each Other - NodeMatcher

NodeMatcher

With the NodeMatcher you can define which nodes should be compared which each other. Even if the test and control nodes are not in the same order.

For Java see NodeMatcher.

AttributeFilter and NodeFilter

NodeTypeMatcher

DifferenceEvaluator

With the DifferenceEvaluator you can re-evaluate the difference of two nodes. If you want ignore some nodes of you XML or evaluate some nodes with your own compare methods, a custom DifferenceEvaluator is the right place for it.

For Java see DifferenceEvaluator.

ComparisonController

The default ComparisionController will let the DifferenceEngine evaluate all differences between test and control xml.
If the evaluation should stop after the first found difference you must use the ComparisonControllers.StopWhenDifferent instead.

See DiffBuilder.withComparisonController()

Getting Results

For the DifferenceEngine you must register a ComparisonListener to handle differences.

Formatting Results

To format a Comparison object to a human readable string you can use the DefaultComparisonFormatter.

For Java see ComparisonFormatter.

DiffBuilder

The DiffBuilder is part of the fluent builder API built on top of the DifferenceEngine, which may cut short some of the features in order to be more convenient to use.

The DiffBuilder provides fluent API style way to generate a Diff-Object. A Diff-Object contains the the control- and test-Source and all discovered Differences.

see DiffBuilder.

CompareMatcher and CompareConstraint

The CompareMatcher is part of the high-level API of XmlUnit built on top of the DiffBuilder that strive to simplify writing unit tests:

	assertThat(test, CompareMatcher.isSimilarTo(control));

see CompareMatcher.