在Spring創(chuàng)建了動態(tài)代理時蔗候,InjectMocks會失效笛园』赘疲可以使用單元測試中的一個工具類(
import org.springframework.test.util.ReflectionTestUtils;)拯辙,手動注入丰涉。
ReflectionTestUtils.setField(aService, "bService", bService);
在Spring創(chuàng)建了動態(tài)代理時蔗候,InjectMocks會失效笛园』赘疲可以使用單元測試中的一個工具類(
import org.springframework.test.util.ReflectionTestUtils;)拯辙,手動注入丰涉。
ReflectionTestUtils.setField(aService, "bService", bService);