如何从TestNG调试配置中检索(x)=参数?

时间:2019-01-16 02:37:07

标签: testng testng-eclipse

我正在尝试使用Eclipse中的Debug Configurations选项调试TESTNG测试,我需要在TestNG测试中获取Program参数。您能帮我完成它吗?

enter image description here

1 个答案:

答案 0 :(得分:2)

您可以在“运行配置”屏幕中通过两种方法将值传递给TestNG

  1. JVM参数。下面的屏幕截图显示了如何通过它们

JVM arguments

  1. 作为环境参数。下面的屏幕截图显示了如何通过它们

Environment arguments

以下示例显示了如何从“运行”配置中读取这些值

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
===============================================