`

XmlUnitTest

XML 
阅读更多
public class XmlUnitTest extends XMLTestCase {

	public XmlUnitTest( String name ) {

		super( name );
	}

	public void testForEquality() throws Exception {

		String myControllerXML = "<msg><uuid>0x00435A8C</uuid></msg>";
		String myTestXML = "<msg><localId>2376</localId></msg>";

		assertXMLNotEqual( "compare", myControllerXML, myTestXML );

	}

	public void testIdentical() throws Exception {

		String myControllerXML = "<struct><int>3</int><boolean>false</boolean></struct>";
		String myTestXML = "<struct><boolean>false</boolean><int>3</int></struct>";

		Diff diff = new Diff( myControllerXML, myTestXML );

		assertTrue( "xml similar:" + diff.toString(), diff.similar() );
		assertFalse( "xml identical:" + diff.toString(), diff.identical() );
	}

	public void testAllDifference() throws Exception {

		String myControlXML = "<news><item id=\"1\">War</item>" + "<item id=\"2\">Plague</item>" + "<item id=\"3\">Famine</item></news>";
		String myTestXML = "<news><item id=\"1\">Peace</item>" + "<item id=\"2\">Health</item>" + "<item id=\"3\">Plenty</item></news>";

		DetailedDiff diff = new DetailedDiff( new Diff( myControlXML, myTestXML ) );

		List<Difference> diffList = diff.getAllDifferences();
		System.err.println( diffList.get( 0 ).getDescription() );
		System.err.println( diffList.get( 0 ).getId() );
		System.err.println( diffList.get( 0 ).getControlNodeDetail().getXpathLocation() );
		System.err.println( diffList.get( 0 ).getTestNodeDetail().getXpathLocation() );
		assertEquals( diff.toString(), 3, diffList.size() );
	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics