Junit中如何获取class的private属性


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 );



你可能感兴趣的:(Junit中如何获取class的private属性)