fxleyu / cu-cafes

This is a repository of Java. And CU is a cafes unders downstairs.
2 stars 0 forks source link

[EasyMock] EasyMock 原理初始 #80

Open fxleyu opened 4 years ago

fxleyu commented 4 years ago

初步了解 Mock 原理,这里使用 EasyMock 来学习。

fxleyu commented 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());
    }
}
fxleyu commented 4 years ago

step 1 helloServe = EasyMock.createMock("helloServeMock", HelloServe.class);

image

fxleyu commented 4 years ago

step 2 EasyMock.expect(helloServe.sayHello()).andReturn("Hello"); image