问题描述
我已经看到了一些关于此的问题,但我似乎无法理解我的特定问题的任何答案。
I've seen a few questions out there regarding this but I can't seem to make sense of any of the answers for my particular problem.
我有一个模拟对象,让我们调用object1,我发送一些方法进行测试,让我们调用testMethod()。所以我最终打电话给
I have a mock object, lets call "object1", which I send to some method for testing, lets call testMethod(). So I end up calling
testMethod(object1);
进行测试。现在在这个testMethod的某个地方,会有一个部分调用方法
for testing. Now somewhere in this testMethod, there will be a part where it calls a method
object1.toggleDisplay();
这是一种void方法。如果方法类似于
which is a void method. If the method were like
object1.getDisplay()
它实际上返回的东西,我通常做
where it actually returns something, I usually do
EasyMock.expect(object1.getDisplay()).andReturn(whatever);
然而,这是一种无效方法,我想测试一下这确实是召唤了一定次数。最简单的方法是什么?
However, this is a void method, and I would like to just test that this has been indeed been called for a certain amount of times. What is the easiest way to do this?
谢谢
推荐答案
如果在过去几年里事情没有改变,那么在设定期望时你会使用 expectLastCall
。
If things haven't changed in the last few years, you use expectLastCall
when setting up your expectations.
object1.toggleDisplay();
object.expectLastCall();
这篇关于如何使用EasyMock测试void方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!