获得例外:
although stubbed methods may return mocks, you cannot inline mock creation (mock()) call inside a thenReturn method (see issue 53)
我正在关注https://code.google.com/p/powermock/wiki/MockitoUsage
PowerMockito.mockStatic(MyUtil.class);
Mockito.when(MyUtil.compareVersion("1","2")).thenReturn(200);
另外我想模拟这个类的部分,这个类中有其他方法,我不想模拟,它们应该像往常一样运行。
详细例外:
org.mockito.exceptions.misusing.UnfinishedStubbingException:
Unfinished stubbing detected here:
-> at org.powermock.api.mockito.internal.PowerMockitoCore.doAnswer(PowerMockitoCore.java:31)
答案 0 :(得分:0)
我无法从您的代码段中看出,但您的测试类中是否有以下注释?
@RunWith(PowerMockRunner.class)
@PrepareForTest(MyUtil.class)
public class MyUtilTest {
此外,您应该查看https://code.google.com/p/powermock/wiki/MockitoUsage13以获取更新版本的PowerMock。