Created
October 19, 2011 06:48
-
-
Save mcs/1297630 to your computer and use it in GitHub Desktop.
Using XMLUnit in JUnit4 to test XML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package learning_tests; | |
import static org.custommonkey.xmlunit.XMLAssert.*; | |
import org.custommonkey.xmlunit.XMLUnit; | |
import org.junit.Test; | |
public class XmlUnitTest { | |
@Test | |
public void compareIdenticalXmlStrings() throws Exception { | |
String xml1 = "<root><node>Test</node></root>"; | |
String xml2 = "<root><node>Test</node></root>"; | |
assertXMLEqual(xml1, xml2); | |
} | |
@Test | |
public void compareSimilarXmlStringsWithoutTolerance() throws Exception { | |
String xml1 = "<root><node>Test</node></root>"; | |
String xml2 = "<root>\n <node>Test</node>\n</root>"; | |
assertXMLNotEqual(xml1, xml2); | |
} | |
@Test | |
public void compareSimilarXmlStringsIgnoringWhitespace() throws Exception { | |
String xml1 = "<root><node>Test</node></root>"; | |
String xml2 = "<root>\n <node> Test </node>\n</root>"; | |
XMLUnit.setIgnoreWhitespace(true); | |
assertXMLEqual(xml1, xml2); | |
} | |
@Test | |
public void compareDifferentXmlStringsIgnoringWhitespace() throws Exception { | |
String xml1 = "<root><node>Test</node></root>"; | |
String xml2 = "<root><node>Te st</node></root>"; | |
XMLUnit.setIgnoreWhitespace(true); | |
assertXMLNotEqual(xml1, xml2); | |
} | |
} |
Hello, it's ok that the compareSimilarXmlStringsWithoutTolerance() if failed ?
thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks import static org.custommonkey.xmlunit.XMLAssert.* was what I needed :-)