This xml-truth module provides a Google Truth extension to compare XML data. It can be used as an alternative to XMLUnit. The basic usage is as follows:


This relies on the following static imports being present:

import static;
import static org.apache.axiom.truth.xml.XMLTruth.xml;

actual and expected are objects that represent XML data. The following types are currently supported:

  • InputStream, Reader, String and byte[] with XML data to be parsed

  • and org.xml.sax.InputSource

  • DOM Document or Element nodes



By default, comparison is strict. E.g. the following assertion would fail:

assertAbout(xml()).that("<p:a xmlns:p='urn:ns'/>").hasSameContentAs("<a xmlns='urn:ns'/>");

To control how the comparison is performed, use the relevant methods on the XMLSubject object returned by that():

        .that("<p:a xmlns:p='urn:ns'/>")
        .hasSameContentAs("<a xmlns='urn:ns'/>");