FEST-Mocks

A Java library which mission is to minimize potential shortcomings of Mock Objects.
Download

FEST-Mocks Ranking & Summary

Advertisement

  • Rating:
  • License:
  • The Apache License 2.0
  • Price:
  • FREE
  • Publisher Name:
  • Alex Ruiz
  • Publisher web site:
  • http://fest.easytesting.org/mocks/index.html

FEST-Mocks Tags


FEST-Mocks Description

A Java library which mission is to minimize potential shortcomings of Mock Objects. FEST-Mocks is a Java library which mission is to minimize potential shortcomings of Mock Objects.EasyMockTemplateOne of the shortcomings of using mocks is introduction of clutter and duplication in our code. Take a look at this example using EasyMock:@Test public void shouldAddNewEmployee() { mockEmployeeDAO.insert(employee); replay(mockEmployeeDAO); employeeBO.addNewEmployee(employee); verify(mockEmployeeDAO);} @Test public void shouldUpdateEmployee() { mockEmployeeDAO.update(employee); replay(mockEmployeeDAO); employeeBO.updateEmployee(employee); verify(mockEmployeeDAO);}The problems with the code listing above are the following:1. There is no clear separation of mock expectations and code to test2. Calls to replay and verify are duplicated3. It is easy to forget to call replay and verify in every test method, which will result in failing testsA solution to this problem is FEST's EasyMockTemplate:@Test public void shouldUpdateEmployee() { new EasyMockTemplate(mockEmployeeDao) { @Override protected void expectations() { mockEmployeeDAO.update(employee); } @Override protected void codeToTest() { employeeBO.updateEmployee(employee); } }.run();}- We have eliminated code duplication (calls replay and verify)- We have a clear separation of mock expectations and code to test- We no longer have to call replay and verify Requirements: · Java SE 5.0 or later


FEST-Mocks Related Software