Expert Spring MVC and Web Flow
brackets—and we call the forPropertymethod and pass firstNameas property name. Next we call the hasErrorCodemethod and pass in t ...
Testing Spring MVC Applications By writing applications that are modular, pluggable, and loosely decoupled you are also cre- ati ...
The basic definition of a unit testis “a discrete test condition to check correctness of an isolated software module.” Although ...
Tools For all of the unit tests in this book, we have used the ubiquitous JUnit (http://www.junit.org) library. It is the de fac ...
It’s possible, however unlikely, that getTotalTravelTime()could alter the values of the start and end objects. If it did manage ...
public void testGetNumberOfLegs() { assertEquals(1, flight.getNumberOfLegs()); } public void testIsNonStopOneLeg() { List legs = ...
List<FlightLeg> legs = new ArrayList<FlightLeg>(); legs.add(new FlightLeg(fooCity, start, barCity, end)); flight = n ...
With the common cases out of the way, take a look at the algorithm you are testing and identify all the branches and decision po ...
Even if you have managed to obtain 100% code coverage from your tests, you’re not necessarily finished writing tests. Code cover ...
What If the Code Has Dependencies? The unit test suggestions, such as testing the smallest amount of code, are quite reasonable ...
To solve this problem, dependencies such as the DAO layer can be replaced by stand-ins called mock objects. Instead of the real ...
We can recommend either jMock or EasyMock for your mock object needs. As noted, Spring uses EasyMock for testing, so you may wan ...
Listing 10-5. AccountServiceImplTest Setup public class AccountServiceImplTest extends MockObjectTestCase { private AccountServi ...
mockAccountDao.verify(); } Notice how the initialization of the mockAccountDaoreads very much like the previous description of t ...
While this test is checking that the correct account was activated, it is also subtly checking that the parameter passed to acti ...
The Spring Framework provides a spring-mock.jarthat includes classes useful for writing both unit tests and integration tests. W ...
Listing 10-9.ActivateAccountController public class ActivateAccountController extends AbstractController { private AccountServic ...
Listing 10-10.ActivateAccountControllerTest Setup public class ActivateAccountControllerTest extends MockObjectTestCase { privat ...
Listing 10-12.testMissingIdParam Method public void testMissingIdParam() throws Exception { request.setMethod("POST"); ModelAndV ...
public void testOK() throws Exception { request.setMethod("POST"); request.addParameter("id", "1"); mockAccountService.expects(o ...
«
11
12
13
14
15
16
17
18
19
20
»
Free download pdf