我想更改应该从哪个 .properties
文件类获取它们。
我的类(class)现在是这样的:
public class MyClass {
private String str;
public MyClass() throws IOException {
loadProperties();
}
private void loadProperties() throws IOException {
Properties props = new Properties();
props.load(getClass().getClassLoader().getResourceAsStream("my.properties"));
str= props.getProperty("property");
}
为什么测试我想从另一个文件加载属性。
这是 apache Camel 应用程序,所以我现在有了这个:
public class ConverterTest {
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new MyClass(); //--> Here i must load from another file
}
@Test
// test
}
这能实现吗?
最佳答案
只需将属性文件名传递给 MyClass 构造函数
public MyClass(String propsFile) throws IOException {
loadProperties(propsFile);
}
关于java - Junit 替换属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19725552/