我刚刚了解到我可以嵌套 TestNG 工厂。耶!但是我不喜欢所有测试名称都相同。这是我的例子:
testng.xml:
<suite>
<test name="TNGTST" >
<classes>
<class name="FactoryLevel1" />
</classes>
</test>
</suite>
FactoryLeve1.java:
import org.testng.annotations.Factory;
public class FactoryLevel1 {
@Factory
public Object[] createTest() {
Object[] res = new Object[3];
for (int i = 1; i <= 3; i++)
res[i - 1] = new FactoryLevel2(i);
return res;
}
}
FactoryLeve2.java:
import org.testng.annotations.Factory;
public class FactoryLevel2 {
int inst;
public FactoryLevel2(int inst) {
this.inst = inst;
}
@Factory
public Object[] createTest() {
Object[] res = new Object[10];
for (int i = 1; i <= 10; i++)
res[i - 1] = new TestClass(i * inst);
return res;
}
}
TestObj.java:
import org.testng.annotations.Test;
public class TestObj {
int inst;
public TestObj(int inst) {
this.inst = inst;
}
@Test
public void printMethod() {
System.out.println("Instance: " + inst);
}
}
我的问题是 Intellij IDEA 显示所有带有名称的测试TNGTST [printMethod()]
,我猜 Jenkins 会为所有测试显示类似的东西(我不知道这些工具是如何获得它的)。我可以以某种方式以非静态方式为测试创建自己的名称吗?