STRUTS

Page 62

49

Getting Started with JUnit

This concludes our coverage of JUnit. You can see how to easy it is to use JUnit to write tests. For the sake of being thorough, here is the complete listing of the HashMapTest: /* * This file was created by Rick Hightower of ArcMinds Inc. * */ package strutsTutorial.junit; import java.util.HashMap; import java.util.Map; import junit.framework.TestCase; import junit.swingui.TestRunner; /** * @author Richard Hightower * ArcMind Inc. http://www.arc-mind.com */ public class HashMapTest extends TestCase{ private Map map; /** Create a HashMap to test. */ protected void setUp() throws Exception { map = new HashMap(); map.put("Larry", "Oracle"); map.put("Bill", "Microsoft"); } public void testRemove() throws Exception{ map.remove("Bill"); assertEquals(1, map.size()); } public void testCount() throws Exception{ assertEquals(2,map.size()); } public void testAdd()throws Exception{ map.put("Rick", "ArcMind"); assertEquals(3, map.size()); } public void testKeyIndex()throws Exception{ assertEquals(map.get("Larry"), "Oracle"); assertNull(map.get("Rick"));

Jakarta Struts Live


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.