我想知道dataprovider是否可以将数据与@Test一起传递给@BeforeTest。我正在编写脚本,我想将一些数据传递给@BeforeTest 并执行一些操作。如果可能的话,请分享逻辑。谢谢
问问题
4431 次
2 回答
1
无法将数据提供者与@BeforeTest
(可能还有任何其他@BeforeX
方法)一起使用,但您可以使用 before@Test
方法,其中所有其他@Test
方法都是依赖的(dependsOnMethods
):
@Test(dataProvider="dp")
public void beforeTest(<params...>) {
<...>
}
@Test(dependsOnMethods="beforeTest") {
<...>
}
但小心点!TestNG 不是 JUnit 然后@BeforeTest
!= @BeforeMethod
。
于 2015-10-14T11:30:40.560 回答
0
有可能的。通过您的 TestNG XML 传递参数并使用 @BeforeClass 中的 ITTestContext 读取它们。
只需使用
context.getCurrentXmlTest().getParameters()
@SuppressWarnings("deprecation")
@BeforeClass
public void setUp(ITestContext context) {
System.out.println(context.getCurrentXmlTest().getParameters());
}
于 2017-10-28T06:33:16.213 回答