我试图查看是否有可能为每个实例化的并行类运行一次安装程序。
如果我具有以下测试类,由于有DataFactory(CSV有2行数据,每个测试有一行),则并行启动两个测试
是否有可能使testSetup()对于TestFu类的每个实例运行一次。 BeforeClass似乎在两个并行测试实例之前都运行过一次。
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>
测试类
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);
}
}
答案 0 :(得分:1)
像这样使用static
标志:
static boolean initialized = false;
@BeforeClass
public void testSetup() {
if (!initialized) {
initialized = true;
System.out.println("Doing setup");
}
}