Open fxleyu opened 4 years ago
代码
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
/**
* @author fxleyu
*/
public class HelloServiceMock {
private HelloServe helloServe;
@Before
public void setUp() {
helloServe = EasyMock.createMock("helloServeMock", HelloServe.class);
}
@Test
public void test() {
EasyMock.expect(helloServe.sayHello()).andReturn("Hello");
EasyMock.replay(helloServe);
Assert.assertEquals("Hello", helloServe.sayHello());
}
}
step 1 helloServe = EasyMock.createMock("helloServeMock", HelloServe.class);
step 2 EasyMock.expect(helloServe.sayHello()).andReturn("Hello");
初步了解 Mock 原理,这里使用 EasyMock 来学习。