我正在Windows上使用Eclipse进行开发,并在Unix上部署代码。我使用System.getProperty("key")获取系统属性值... 我该如何在Eclipse中传递这些值,以便不必修改代码并且可以在Eclipse中进行调试?
有什么建议吗?
运行 -> 运行配置, 选择项目, 第二个选项卡: “参数”。顶部框是你的程序,底部框是VM参数,例如:-Dkey=value
。
您可以使用 Java 的 System.properties
,若要从 Eclipse 中使用它们,您可以:
Run Configuration
的 VM 参数中添加 -Dlabel="label_value"
,如下所示:然后运行测试:
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class Main {
@Test
public void test(){
System.out.println(System.getProperty("label"));
assertEquals("label_value", System.getProperty("label"));
}
}
最后它应该通过测试并在控制台中输出以下内容:
label_value
这将适用于JUnit。对于TestNG,请使用以下命令
-ea -Dmykey="value" -Dmykey2="value2"
是的,这就是方法:
右击您的程序,选择运行 -> 运行配置, 然后在 VM 参数中。
-Denv=EnvironmentName -Dcucumber.options="--tags @ifThereisAnyTag"
然后您可以应用并关闭。