如何在从 shell 脚本调用 testng xml 时设置系统属性

How to set system properties while calling testng xml from the shell script

我的要求如下

我有一个 shell 脚本,它将 运行 testng.xml(它 运行 是 testng 脚本)。所以我必须在调用 testng.xml 时设置系统属性,实习生调用 testng 脚本(这些 testng java 文件正在使用系统属性)

谁能帮我解决这个问题?

根据您在 Java 生态系统中启动 TestNG 的方式,您始终可以在 -D 选项后自由使用系统属性,如下所示:

java -Dprop.key="property value" appToRun

然后您可以以常用方式访问这些属性...

System.getProperty("prop.key");