Friday, April 10, 2009

XmlUnit

XmlUnit is an insanely great tool. It has saved me a ton of time in the past few weeks.

I log the differences from my unit test like this :

        XMLUnit.setIgnoreWhitespace(true);
Diff xmlDiff = new Diff(expectedXml, result);

DetailedDiff myDiff = new DetailedDiff(xmlDiff);
List<Difference> allDifferences = myDiff.getAllDifferences();
for(Difference d : allDifferences){
log.debug("difference : " + d);
}


The "result" string comes from a Groovy class using XmlSlurper. Also I usually generate "expectedXml" from a Groovy class.

No comments: