import junit.framework.*; import java.io.*; import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; import org.w3c.dom.*; public class XmlTest extends TestCase{ public void testArv1(){ try{ Document d=DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("aadressikogu.xml"); NodeList tabelid=d.getFirstChild().getChildNodes(); assertEquals(tabelid.getLength(), 3); } catch (Exception viga){viga.printStackTrace();} } public void testArv2(){ try{ BufferedReader sisse=new BufferedReader( new FileReader("aadressikogu.xml") ); int k=0; String rida=sisse.readLine(); while(rida!=null){ rida=sisse.readLine(); k++; } if(k==2){ assertEquals(k, 2); } sisse.close(); } catch (Exception viga){viga.printStackTrace();} } public static void main(String[] argumendid){ junit.textui.TestRunner.run(new TestSuite(XmlTest.class)); } } /* javac -classpath junit.jar;. XmlTest.java java -cp junit.jar;. XmlTest .. Time: 0,33 OK (2 test) */