Why @InjectMocks Does Not Support Mixed Dependency Injection?

114 views
Skip to first unread message

reddi prit

unread,
Mar 23, 2022, 4:22:54 PM3/23/22
to mockito
Recently I encountered a problem when I wrote a Junit test case using Mockito. I got to know that it happened because I used mixed dependency in Google Guice. I used constructor & setter injection both in my test class. The dependency injected by setter became null when I tried used @InjectMocks annotation on my test class.


But I am not able to understand why Mockito designed it like this. Mixed dependency works when I use MockitoAnnotations.initMocks(), but not with @InjectMocks. Both should work same way, either support mixed dependencies or not. Anyone knows why?
Reply all
Reply to author
Forward
0 new messages