|
From: Harald B. <bra...@gm...> - 2014-09-12 09:06:55
|
Hi Gordon,
you must set 'XMLUnit.setIgnoreWhitespace(true);' somewhere before:
@Test
public void testXmlTest1() throws Exception {
Diff compareXML;
final String source = "<stuff-doc><stuff>Stuff Stuff Stuff</stuff><more-stuff>Some More Stuff</more-stuff></stuff-doc>";
final String test = "<stuff-doc>\n<stuff>Stuff Stuff Stuff</stuff>\n<more-stuff>Some More Stuff</more-stuff>\n</stuff-doc>";
// OUTPUT:
// identical: false
// similar: false
compareXML = XMLUnit.compareXML(source, test);
System.out.println("identical: " + compareXML.identical());
System.out.println("similar: " + compareXML.similar());
// OUTPUT with ignoreWhitespaces = true:
// identical: true
// similar: true
XMLUnit.setIgnoreWhitespace(true);
compareXML = XMLUnit.compareXML(source, test);
System.out.println("identical: " + compareXML.identical());
System.out.println("similar: " + compareXML.similar());
Assert.assertTrue(compareXML.toString(), compareXML.similar());
}
lg,
Harry
On 2014-05-09, Gordon Ross wrote:
> My code is:
> public void testXmlTest1() throws SAXException, IOException
> {
> String source = "<stuff-doc><stuff>Stuff Stuff Stuff</stuff><more-stuff>Some More Stuff</more-stuff></stuff-doc>";
> String test = "<stuff-doc>\n<stuff>Stuff Stuff Stuff</stuff>\n<more-stuff>Some More Stuff</more-stuff>\n</stuff-doc>";
> assertXMLEqual(source, test);
> }
> XMLUnit is saying they are not the same as the number of children of
> <stuff-doc> is 5, not 2. Well, that’s true because of the whitespace
> creating text nodes. But I thought XMLUnit was supposed to cope with
> this?
|