技术开发 频道

Mock测试工具之EasyMock教程

  execute()方法将为我们打印出toString()和hashCode()方法的结果。

public class LimitationTest {

    
private Business      business;

    
private IMocksControl mocksControl;

    
private Service       service;

    @Before
    
public void init() {
        business
= new Business();
        mocksControl
= EasyMock.createStrictControl();
        service
= mocksControl.createMock(Service.class);
        business.setService(service);
    }

    @Test
    
public void testDefaultBehavior() {
        business.execute();
    }

    @Test
    
public void testCustomizedBehavior() {

        EasyMock.expect(service.toString()).andReturn(
"Customized toString");
        EasyMock.expect(service.hashCode()).andReturn(
100000);
        mocksControl.replay();

        business.execute();
        mocksControl.verify();
    }
}
0
相关文章