检测到未完成的短截线

时间:2015-09-18 13:44:40

标签: java mockito powermockito

使用mockito时,我的代码中出现以下错误:

org.mockito.exceptions.misusing.UnfinishedStubbingException: 
Unfinished stubbing detected here:
-> at org.powermock.api.mockito.internal.PowerMockitoCore.doAnswer(PowerMockitoCore.java:36)

E.g. thenReturn() may be missing.
Examples of correct stubbing:
    when(mock.isOk()).thenReturn(true);
    when(mock.isOk()).thenThrow(exception);
    doThrow(exception).when(mock).someVoidMethod();
Hints:
 1. missing thenReturn()
 2. you are trying to stub a final method, you naughty developer!
 3: you are stubbing the behaviour of another mock inside before 'thenReturn' instruction if completed

导致此问题的堆栈跟踪:

PageCodeBase mockPageCodeBase = Mockito.mock(PageCodeBase.class);
        Map<String, String> nn = getStringV();
        when(mockPageCodeBase.getRequestParam()).thenReturn(nn);

private Map<String, String> getStringV(){
        Map<String, String> mapV = new HashMap<String, String>();
        mapV.put("selectedApplicantId", "selectedApplicantId");
        return mapV;
    }

我在这里想念任何事情

1 个答案:

答案 0 :(得分:1)

删除PowerMockito.doNothing()。when(ASKService.class); 关于@Before的声明我的作品。