java - 在TestNG中动态添加参数到@beforeclass

标签 java testng

我需要使用 TestNG 类向 @BeforeClass 方法添加参数。 我正在使用以下代码动态运行 TestSuite:

List<XmlSuite> suites = getXmlTestSuiteForUI(xmlName);

TestNG testNG = new TestNG();

testNG.setXmlSuites(suites);
testNG.setPreserveOrder(true);
testNG.addListener(testListenerAdapter);

testNG.run();

如何向 @BeforeClass 方法添加参数?

类似这样的东西,但不是 test.setParameters 类似 beforeclass.addParameters 的东西。

for (XmlSuite suite : suites){
    for(XmlTest test : suite.getTests()){
        test.setParameters(params);
    }
}

最佳答案

setParameters 也可在 XmlClass 上使用。

for (XmlSuite suite : suites) {
    for(XmlTest test : suite.getTests()) {
        for(XmlClass clazz : test.getXmlClasses()) {
            clazz.setParameters(params);
        }
    }
}

关于java - 在TestNG中动态添加参数到@beforeclass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33236924/

相关文章:

java - 与 Runtime.exec() 的参数作斗争

java - junit 中是否有 @AfterMethod 的替代方案?

multithreading - 在Logback中记录并行线程

java - Selenide 测试因 org/openqa/selenium/NoSuchSessionException 失败

hibernate - 使用 TestNg 测试 hibernate ,单独运行时测试通过但在套件中失败

java - 我想动态访问循环中的变量

Camera.open() 上的 java.lang.RuntimeException : Fail to connect to camera service.;

java - 从外部存储打开图像

java - 帮助理解伪代码

java - 设置 JFrame 背景透明使 PopupMenu 空白