Extending the Test Suite
Before extending the test suite, it's helpful to review the automatically generated test cases. For example, Listing One is a sample test that's automatically generated for the com.ibatis.jpetstore.domain.Order class (specifically, its initOrder() method). Notice how the tool automatically generated input data to use for the test. At the same time, it created assertions based on the observed state of the objects at the end of the test. This now becomes a test that you can always rerun against the Order class to confirm that its behavior remains intact as you are extending and modifying it.
Further, you can extend the automatically generated test suite either by manually adding more test cases or by modifying the automatically generated tests to use realistic data, check specific assertions, or test various functional scenarios that you may be interested in. Here is an example of a test for the initOrder() method in the com.ibatis.jpetstore.domain.Order class. Listing Two (available online at http://www.ddj.com/code/) is a test created by manually extending one of the automatically generated tests to add more logical, realistic dataas well as to add more assertions.
/** * Test for method: initOrder(com.ibatis.jpetstore.domain.Account,com.ibatis.jpetstore.domain.Cart) */ public void testInitOrder21() throws Throwable { Order testedObject = new Order(); Account account = new Account(); Cart cart = new Cart(); account.setUsername("username1"); account.setPassword("password0"); account.setEmail("email0"); account.setFirstName("firstName0"); account.setLastName("lastName0"); account.setStatus("status1"); account.setAddress1("140 East 45th Street, New York, NY 10017"); account.setAddress2("1600 Pennsylvania Avenue NW, Washington, DC 20500"); account.setCity("Tokyo"); account.setState("New York"); account.setZip("90011-1234"); account.setCountry("England"); account.setPhone("1234567"); account.setFavouriteCategoryId("favouriteCategoryId0"); account.setLanguagePreference("languagePreference0"); account.setListOption(false); account.setBannerOption(false); account.setBannerName("bannerName0"); testedObject.initOrder(account, cart); assertNotNull(testedObject.getLineItems()); assertEquals(0, testedObject.getLineItems().size()); assertNotNull(testedObject.getOrderDate()); assertEquals(new java.util.Date().toString(), testedObject.getOrderDate().toString()); assertNotNull(testedObject.getTotalPrice()); assertEquals("0", testedObject.getTotalPrice().toString()); assertEquals("P", testedObject.getStatus()); assertEquals(0, testedObject.getOrderId()); assertEquals("username1", testedObject.getUsername()); assertEquals("140 East 45th Street, New York, NY 10017", testedObject.getShipAddress1()); assertEquals("1600 Pennsylvania Avenue NW, Washington, DC 20500",testedObject.getShipAddress2()); assertNotNull(cart.getAllCartItems()); assertNotNull(cart.getCartItems()); }
Over time, you might want to further improve the intelligence of the regression test suite by using automated tools that record interactions with a running application, then produce functional JUnit tests representing the recorded interactions. Listing Three (available online) is an example of a front-end JUnit test that represents a scenario of purchasing a dog and a cat, then validates that the total for this order is $112.