1
当使用MockFor时,我如何才能验证n方法是否被调用至少?我试着忽略设立后需求的方法调用,就像这样:使用MockFor,如何验证一个方法被调用至少n次?
import groovy.mock.interceptor.MockFor;
import org.junit.Test
class FilterTest {
interface Filter {
boolean isEnabled()
}
@Test
public void test() {
MockFor mockContext = new MockFor(Filter)
// Expect at least one call
mockContext.demand.isEnabled {true}
mockContext.ignore.isEnabled {false}
// Obtaining a usuable mock instance
def filter = mockContext.proxyInstance()
// Fake calling the method
filter.isEnabled()
filter.isEnabled()
// Verify invoked at least once?
mockContext.verify(filter)
}
}
不过,我得到一个断言失败:
junit.framework.AssertionFailedError: verify[0]: expected 1..1 call(s) to
'isEnabled' but was called 0 time(s).
谢谢,那正是我之后的! – Klarth 2013-02-14 10:58:20