本文翻译自:Difference between @Mock and @InjectMocks
Mockito框架中的@Mock
和@InjectMocks
什么区别?
#1楼
参考:https://stackoom.com/question/175zp/Mock和-InjectMocks之间的区别
#2楼
@Mock
creates a mock. @Mock
创建了一个模拟。 @InjectMocks
creates an instance of the class and injects the mocks that are created with the @Mock
(or @Spy
) annotations into this instance. @InjectMocks
创建该类的实例,并将使用@Mock
(或@Spy
)注释创建的@Spy
注入此实例。
Note that you must use @RunW