1

获取异常:

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)
4

1 回答 1

0

我无法从您的代码片段中看出,但您的测试类中有以下注释吗?

@RunWith(PowerMockRunner.class)
@PrepareForTest(MyUtil.class)
public class MyUtilTest {

此外,您应该查看https://code.google.com/p/powermock/wiki/MockitoUsage13以获得更新版本的 PowerMock。

于 2013-03-22T14:13:35.040 回答