【发布时间】:2015-10-11 04:40:51
【问题描述】:
我有一个 ReadPropertyFile 类,其中包含名为 getPropertyFor 的方法,该方法返回给定键的值作为参数。我从其他类调用的 getPropertyFor() 方法,使用键作为输入参数。我的属性 filetestConfig.properties(file name) 的内容是: FILE_NAME=D:/Refreshed_data_daily/all_hue_posts_in_excel.xlsx
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) {
return properties.getProperty(key);
}
}
@Test
public void testFilePathValueInConfigFile(){
assertEquals(propertyFileObj.getPropertyFor(keyForFilePath), "D:/Refreshed_data_daily/all_hue_posts_in_excel.xlsx");
}
上面的测试用例是检查函数返回的值是否正确。如何检查密钥是否正确?什么是可能的测试用例来测试关键。而且我不想出于测试目的更改我的 testConfig.properties 文件。 我需要帮助,我是 Java Junit 测试的新手。
【问题讨论】:
-
您究竟要检查什么密钥?密钥是否存在于属性文件中?或者你想根据值找到键?
-
我想检查属性文件中是否存在密钥。如何检查?
-
只做 assertNotNull(properties.getProperty(FILE_NAME)
-
这个测试实际上会检查键 FILE_NAME 对应的值是否不为空!
标签: java junit key properties-file