如何从 TestNG 调试配置中检索 (x) = Arguments?
How do I retrieve (x) = Arguments from TestNG debug configuration?
我正在尝试使用 Eclipse 中的调试配置选项调试 TESTNG 测试,我需要在我的 TestNG 测试中获取程序参数。你能帮我完成吗?
您可以在 运行 配置屏幕中通过两种方式将值传递给 TestNG
- JVM 参数。下面的截图显示了如何传递它们
- 作为环境参数。下面的截图显示了如何传递它们
下面的示例显示了如何从 运行 配置中读取这些值
import org.testng.annotations.Test;
public class HelloWorldTestClass {
@Test
public void testMethod() {
//This is how we read values provided via the Environment tab section of the run configuration.
String environment = System.getenv("env");
//This is how we read values provided via the VM arguments section
String browser = System.getProperty("browser");
System.err.println("Running on [" + browser + "] in the environment [" + environment + "]");
}
}
下面是执行的输出:
[RemoteTestNG] detected TestNG version 6.14.3
Running on [Opera] in the environment [Production]
PASSED: testMethod
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
我正在尝试使用 Eclipse 中的调试配置选项调试 TESTNG 测试,我需要在我的 TestNG 测试中获取程序参数。你能帮我完成吗?
您可以在 运行 配置屏幕中通过两种方式将值传递给 TestNG
- JVM 参数。下面的截图显示了如何传递它们
- 作为环境参数。下面的截图显示了如何传递它们
下面的示例显示了如何从 运行 配置中读取这些值
import org.testng.annotations.Test;
public class HelloWorldTestClass {
@Test
public void testMethod() {
//This is how we read values provided via the Environment tab section of the run configuration.
String environment = System.getenv("env");
//This is how we read values provided via the VM arguments section
String browser = System.getProperty("browser");
System.err.println("Running on [" + browser + "] in the environment [" + environment + "]");
}
}
下面是执行的输出:
[RemoteTestNG] detected TestNG version 6.14.3
Running on [Opera] in the environment [Production]
PASSED: testMethod
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================