@InjectMocks
@Autowired
private TestClass testClass;
@Mock
private TestClassPropertyA testClassPropertyA;
//TestClass 若只想mock TestClass 其中的属性testClassPropertyA,其他属性仍使用真实调用;
//则需要对TestClass的属性加上setter方法
Mockito与Spring中@Autowired与@InjectMocks组合
最新推荐文章于 2025-03-15 21:27:59 发布