Quite a while ago, I wrote about using XMLUnit in my unit tests to compare XML results.
The method used to create Diffs has been useful, but the project offers a simpler way to compare XML:
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual
class AssertXmlEqualTest {
@Test void test_xml_is_similar() {
def expected = "<hi>bye</hi>"
def actual = "<hi>bye</hi>"
assertXMLEqual expected, actual
}
}
def actual = "<hi>goodbye</hi>"
The test fails as the XML documents are no longer similar:
junit.framework.AssertionFailedError: org.custommonkey.xmlunit.DiffSince I have no reason in this simple case to be inspecting the Diff object created by XMLUnit as described in the previous posting, this method should serve as a nice substitute.
[different] Expected text value 'bye' but was 'goodbye' -
comparing <hi ...>bye<hi> at /hi[1]/text()[1] to <hi ...>goodbye<hi> at /hi[1]/text()[1]
No comments:
Post a Comment