public class SubObject {
@Inject
private TradeService tradeService;
public void onload(){
tradeService.test();
}
}
在JunitTest时如何获取advanceservice和tradeService 属性
SubObject subObject = new SubObject();
TradeService tradeService = mock(TradeService.class);
Field tradeServiceField = subObject.getClass().getDeclaredField("tradeService");
tradeServiceField.setAccessible(true);
tradeServiceField.set(subObject , tradeService );
转载于:https://blog.51cto.com/angelgirl/1672582