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

后端 未结 9 2334
终归单人心
终归单人心 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:45

    You need to create a MOCK of pcUserService first, and then use that mock.

    PcUserService mock = org.mockito.Mockito.mock(PcUserService.class);
    when(mock.read("1")).thenReturn(pcUser);
    

提交回复
热议问题