publicclassSubObject{
@Inject
privateTradeServicetradeService;
publicvoidonload(){
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 );