The document discusses various features of EasyMock, a Java testing framework for creating mock objects to test code in isolation, including how to create different types of mocks, define return values and argument matchers, and integrate EasyMock with the Unitils testing framework. It provides examples of using EasyMock to mock objects, define expected method calls and return values, and verify interactions for unit testing purposes.
2. Developer tests - big theory Why/when short feedback loop Classic vs mock testing http://martinfowler.com/articles/mocksArentStubs.html Failing legacy tests check if can be fixed; if not separate from working ones
3. EasyMock mock types (1) normal mocks expect ¨C replay ¨C verify @ Before public void setUp() { userDao = EasyMock. createMock (UserDao. class ); validator = new UserValidator( userDao ); } @ Test public void duplicateLoginNameIsInvalid() throws Exception { User user = ... errors = new BindException(user, "User" ); EasyMock.expect( userDao .isValidLoginName(user)).andReturn( false ); EasyMock.replay( userDao ); validator .validate(user, errors); assertTrue(errors.toString(), errors.hasErrors()); EasyMock.verify( userDao ); }
8. if cannot implement nice equals for some argument (but there is better alternative!) filterDao = createNiceMock(FilterDao. class ); //expect(filterDao.getFilterId("unique-filter-name", USER_ID)).andReturn(null); replay( filterDao ); validator.validate(filter, errors); assertFalse(errors.hasErrors()); verify( filterDao );
9. Argument matchers when to use if default equals based check doesn't work predefined matchers eq(X value)