[英]TestNG - How to run setup once before all tests in a class for each parallel run
I am trying to see if it is possible to have a setup run once for each parallel class instantiated. 我试图查看是否有可能为实例化的每个并行类运行一次安装程序。
If I have the following test class, because of the DataFactory (CSV has 2 rows of data, one for each test), two tests are started in parallel 如果我具有以下测试类,由于有DataFactory(CSV有2行数据,每个测试有一行),则将并行启动两个测试
Is it possible to get testSetup() to run once for each instance of the TestFu class. 是否有可能使testSetup()对于TestFu类的每个实例运行一次。 BeforeClass seems to run it once before both parallel test instances.
BeforeClass似乎在两个并行测试实例之前都运行过一次。
TestXML TestXML
<suite name="SomeTest" parallel="none" thread-count="20" verbose="2">
<test name="Graph+APITests" parallel="instances" thread-count="5">
<classes>
<class name="TestFu" />
</classes>
</test>
</suite>
Test Class 测试班
public class TestFu {
String var1;
@Factory(dataProvider = "testStuff")
public TestFu(String var1, String var2) {
this.var1 = var1;
this.var2 = var2;
}
@DataProvider(name = "testStuff")
public static Object[][] stuff() {
return methodThatLoadsVarsFromCSV;
}
@BeforeClass
public void testSetup() {
System.out.println("Doing setup");
}
@Test
public void testOne() {
System.out.println("Test 1 " + this.var1);
}
@Test
public void testTwo() {
System.out.println("Test 2 " + this.var2);
}
}
Use static
flag like this: 像这样使用
static
标志:
static boolean initialized = false;
@BeforeClass
public void testSetup() {
if (!initialized) {
initialized = true;
System.out.println("Doing setup");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.