Multiple levels of @Mock and @InjectMocks

后端 未结 4 1326
星月不相逢
星月不相逢 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 14:02

    Other solution I found is using java sintax instead annotation to make the @Spy object injected.

    @Spy
    private MockObject1 mockObject1 = new MockObject1 ();
    
    @InjectMocks //if MockObject2 has a MockObject1, then it will be injected here.
    private MockObject2 mockObject2 = spy(MockObject2.class);
    
    @InjectMocks
    private SystemUnderTest systemUnderTest;
    

提交回复
热议问题