jeudi 6 août 2015

Reflection - Set Private field in controller spring

I use Spring MVC.

I have a private field in my controller. The value for this field comes from the properties file as,

@Controller
public Class MainController() {

   @Value("${my-value}")
   private int myValue;

}

I have to override the value in for the selenium tests. How can I override the value for this field, means I want to set a customized value (so that the value is not taken from property file)?

Can it be like this,

ReflectionTestUtils.setField(MainController.class, "myValue", 3, Integer.class);





Aucun commentaire:

Enregistrer un commentaire