[英]java.lang.IllegalStateException: no last call on a mock available for static method
im new to junit mocking. 我是junit模拟的新手。 and im trying to mock below line. 和即时通讯试图嘲笑线以下。
IsomeInterface someinterface = someClass.getInstance();
where someClass
is implementation of IsomeInterface
. 其中someClass
是实施IsomeInterface
。 and getInstance
is a static method which returns someClass
object. getInstance
是一个静态方法,该方法返回someClass
对象。 below is the mocking i tried. 下面是我尝试过的嘲笑。
someClass someClassMock= PowerMock.createMock(someClass.class);
EasyMock.expect(someClass.getInstance()).andReturn(someClassMock);
exception: 例外:
java.lang.IllegalStateException: no last call on a mock available
at org.easymock.EasyMock.getControlForLastCall(EasyMock.java:560)
at org.easymock.EasyMock.expect(EasyMock.java:538)
Try 尝试
PowerMock.mockStatic(ClassThatContainsStaticMethod.class)
to mock all methods of this class. 模拟此类的所有方法。
Also there can be a problem in constructing mock via powermock and verify them by easymock so try: 通过powermock构造模拟并通过easymock验证它们也可能存在问题,因此请尝试:
PowerMock.expectNew(NewInstanceClass.class).andReturn(mockObject)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.