Mockito Exception - when() requires an argument which has to be a method call on a mock

后端 未结 9 2343
终归单人心
终归单人心 2020-12-15 15:12

I have a very simple test case that is using Mockito and Spring Test framework. When I do

when(pcUserService.read(\"1\")).thenReturn(pcUser);
9条回答
  •  渐次进展
    2020-12-15 15:41

    Another solution to this issue might be that in case of a test class that is using PowerMockRunner, you might have to add the class that you are mocking to the list, in @PrepareForTest annotation.

    For instance -

    @PrepareForTest({ PcUserService.class })

提交回复
热议问题