How to resolve Unneccessary Stubbing exception

前端 未结 13 1459
无人共我
无人共我 2020-12-24 03:57

My Code is as below,

@RunWith(MockitoJUnitRunner.class)
public class MyClass {

    private static final String code =\"Test\";

    @Mock
     private MyCl         


        
13条回答
  •  情深已故
    2020-12-24 04:38

    For me neither the @Rule nor the @RunWith(MockitoJUnitRunner.Silent.class) suggestions worked. It was a legacy project where we upgraded to mockito-core 2.23.0.

    We could get rid of the UnnecessaryStubbingException by using:

    Mockito.lenient().when(mockedService.getUserById(any())).thenReturn(new User());
    

    instead of:

    when(mockedService.getUserById(any())).thenReturn(new User());
    

    Needless to say that you should rather look at the test code, but we needed to get the stuff compiled and the tests running first of all ;)

提交回复
热议问题