我试图在类中模拟静态方法。
PowerMock.mockStatic(WebUtils.class);
EasyMock.expect(WebUtils.getRequest(EasyMock.anyObject(Object.class))).andReturn(httpServletRequest).anyTimes();
PowerMock.replayAll();
getRequest
是非最终的静态方法。在第二行,JUnit引发错误。
java.lang.IllegalStateException: no last call on a mock available
at org.easymock.EasyMock.getControlForLastCall(EasyMock.java:520)
at org.easymock.EasyMock.expect(EasyMock.java:498)
at --
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:68)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:310)
Powermock版本:1.6.2&使用PowerMockRunner.h运行测试类
答案 0 :(得分:2)
检查您是否正确设置了@PrepareForTest
注释。