I have a class ReadPropertyFile which has a method getPropertyFor() of return type string(which is the value corresponding to key passed as parameter).I need help to test the getPropertyFor() method for both value and the key using Junit.
public class ReadPropertyFile {
private Properties properties;
public ReadPropertyFile(String propertyFileName) {
properties= new Properties();
try {
properties.load(new FileReader(propertyFileName));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public String getPropertyFor(String key) {
String value = properties.getProperty(key);
if(value == null) {
try {
throw new Exception(key + " not found!");
} catch (Exception e) {
e.printStackTrace();
}
}
return value;
}
}
I have written the following test case to test the value for the key provided.
How do I test the "key" whether it is contained in the testconfig.properties file? The contents of the testConfig.properties are as follows: FILE_NAME=D:/Refreshed_data_daily/all_hue_posts_in_excel.xlsx
Aucun commentaire:
Enregistrer un commentaire