如何使用EasyMock期望 [英] How to use EasyMock expect
本文介绍了如何使用EasyMock期望的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
预期对我来说似乎不起作用:
The expect doesn't seem to work for me:
package com.jjs.caf.library.client.drafting;
import static org.junit.Assert.*;
import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
import com.jjs.caf.library.client.CustomerManager;
import com.jjs.caf.library.client.UserBookLimiter;
public class DraftTest {
UserBookLimiter userBookLimiter;
int expected = 5;
@Before
public void setUp() throws Exception {
userBookLimiter = EasyMock.createMock(UserBookLimiter.class);
EasyMock.expect(userBookLimiter.getMaxNumberOfBooksAllowed()).andReturn(5);
}
@Test
public final void test() {
assertEquals(expected, userBookLimiter.getMaxNumberOfBooksAllowed());
}
}
它应该是5,但是我得到的0好像期望不会在那里...
It's supposed to be 5, but I'm getting 0 as if the expect wouldn't be there at all...
推荐答案
好的,经过分析我终于通过添加
Okay, after analysing I finally got it to work by adding
EasyMock.replay(userBookLimiter);
因此设置方法如下所示:
So the setup method looks like this:
@Before
public void setUp() throws Exception {
userBookLimiter = EasyMock.createMock(UserBookLimiter.class);
EasyMock.expect(userBookLimiter.getMaxNumberOfBooksAllowed()).andReturn(5);
EasyMock.replay(userBookLimiter);
}
这篇关于如何使用EasyMock期望的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文