Multiple levels of @Mock and @InjectMocks

后端 未结 4 1327
星月不相逢
星月不相逢 2021-02-01 13:07

So I understand that in Mockito @InjectMocks will inject anything that it can with the annotation of @Mock, but how to handle this scenario?

@Mock
private MockOb         


        
4条回答
  •  故里飘歌
    2021-02-01 13:51

    Since I didn't get any response here I asked on the Mockito forums. Here is a link to the discussion: https://groups.google.com/d/topic/mockito/hWwcI5UHFi0/discussion

    To summarize the answers, technically this would kind of defeat the purpose of mocking. You should really only mock the objects needed by the SystemUnderTest class. Mocking things within objects that are themselves mocks is kind of pointless.

    If you really wanted to do it, @spy can help

提交回复
热议问题