@Mock创建一个模拟。@InjectMocks创建该类的实例,并将使用@Mock(或@Spy)注释创建的模拟注入该实例。请注意,您必须使用@RunWith(MockitoJUnitRunner.class)或Mockito.initMocks(this)初始化这些模拟并注入它们。@RunWith(MockitoJUnitRunner.class)public class SomeManagerTest { @InjectMocks private SomeManager someManager; @Mock private SomeDependency someDependency; // this will be injected into someManager //tests...}