1
我有一个Propertyfile config.properties
其中我存储了一个类加载读取文件的路径。 属性加载这样的:如何覆盖您的Propertyfile的jUnit(maven)
public class PropertyConfig {
private static final Properties properties = new Properties();
static {
try {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties"));
} catch (IOException e) {
throw new ExceptionInInitializerError(e);
}
}
public static String getSetting(String key) {
return properties.getProperty(key);
}
}
,并在相关类的调用是这样的:
private static File savedGamesFolder = new File(PropertyConfig.getSetting("folder_for_saved_games"));
出于测试目的,我希望能够将路径更改到测试目录,或者在jUnit-TestCase中更改整个Property文件。如何实现这一目标?
我正在使用Maven,如果有帮助。
如果将'config.properties'放在'src/main/resources'中,它就可以将新的'src/test/resources'放入。 – 2013-05-10 03:30:09