File Based Data Provider

here is my script. In my Junit tests in many places, I need to specify a username, description, URL, invalid URL, etc. Therefore, I hard-coded these values. Good hard coding everywhere. So I want to move these values ​​to a central location (file). And I have some data provider that says DP. I can call DP.getUserName (), DP.getUrl (), etc. In those places where these values ​​are needed. Also, I want to have a pool of different usernames, URLs, invalid URLs, etc. When I call getUrl, it will randomly receive from the pool.

What I can come up with is to use java.util.Properties to load the propertis from the file, and every time I call, I just accidentally return one entry.

Any best approach to achieve this? thank.

+3
source share
1 answer

A properties file is a good idea, it also allows you not to recompile the code when the element changes. The getUrl output from the pool is fine.

However, if you have multiple getUserName (), getErrorURL (), getDatabaseName (), etc. that all return a String. You might want to think about saving these properties of a single key on a map in your DP class and provide a list of open lists for accessing variables.

Sort of:

 private Map<PROP, String> map;
 public enum PROP{ USERNAME, PASSWORD, DATABASE_NAME};

 public String getProperty(PROP key){
     return map.get(key);
 }

Thus, you do not need to add a new method and variable for each property;

0
source

Source: https://habr.com/ru/post/1785308/


All Articles