From: Stefan B. <bo...@ap...> - 2009-12-15 13:01:29
|
On 2009-12-15, Dubey, Tarun <Tar...@sa...> wrote: > The following test case fails while according to the javadocs of > similar() method in Diff this should pass > @Test > public void testXmlIgnoreOrder() throws IOException, SAXException { > XMLUnit.setIgnoreWhitespace(true); > XMLUnit.setIgnoreAttributeOrder(true); > String xml1 = > "<TEST><FLIGHT NUM=\"121\"></FLIGHT><FLIGHT > NUM=\"122\"></FLIGHT></TEST>"; > String xml2 = > "<TEST><FLIGHT NUM=\"122\"></FLIGHT><FLIGHT > NUM=\"121\"></FLIGHT></TEST>"; > Diff diff = XMLUnit.compareXML(xml1, xml2); > Assert.assertTrue(diff.similar()); > } No, it should fail. IgnoreAttributeOrder affects whether the order of attributes of a single element is significant. All your elements only have a single attribute, so order of them is the same anyway. What is different is the order of elements. If the order of elements is not significant to you, you'll have to help XMLUnit decide which elements to compare by overriding the ElementQualifier. The default implementations only looks at element names, if the names are the same, it will compare the elements. > Surprisingly the same test passes if the element names are different as > shown below > "<TEST><FLIGHT NUM=\"121\"></FLIGHT><CRUISE > NUM=\"122\"></CRUISE></TEST>"; Yes. If the names are different, the FLIGHT elements and the CRUISE elements get matched against each other. If they are the same, XMLUnit will match them in the order they occur. You want to use an ElementNameAndAttributeQualifier <http://xmlunit.sourceforge.net/userguide/html/ar01s03.html#ElementNameAndAttributeQualifier> Stefan |