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