Skip to content

Latest commit

 

History

History
50 lines (44 loc) · 1.28 KB

assert-xml-baseline.md

File metadata and controls

50 lines (44 loc) · 1.28 KB

XML

XML support is added through xml-unit.

import static io.github.goatfryed.assert_baseline.Assertions.assertThatXml;

assertThatXml(xmlString)
    .isEqualToBaseline("src/test/resources/specs/my.baseline.xml");

Include in your project

For gradle

    implementation("io.github.goatfryed:assert-baseline:1.0.0-alpha1-SNAPSHOT") {
        capabilities {
           requireCapability("io.github.goatfryed:assert-baseline-xml")
        }
    }

For maven

<dependencies>
    <dependency>
        <groupId>io.github.goatfryed</groupId>
        <artifactId>assert-baseline</artifactId>
        <version>{version}</version>
    </dependency>
    <dependency>
        <groupId>org.xmlunit</groupId>
        <artifactId>xmlunit-assertj</artifactId>
        <version>2.10.0</version>
    </dependency>
</dependencies>

Tips & Recipes

Ignore auto-generated, volatile fields

import static io.github.goatfryed.assert_baseline.xml.XmlDiffConfiguration.ignoringXPath;

assertThatXml(xmlContent)
    .usingXmlComparator(diff -> diff
        .withNodeFilter(
            ignoringXPath("/root/event/uuid")
            .and(ignoringXPath("/root/event/timestamp"))
            ::test
        )
    ).isEqualToBaseline(pathToBaseline);