TestNGファクトリをネストできることを知りました。わーい!しかし、私はすべてのテスト名が同じであることを好まない。これは私の例である: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()]
のすべてのテストを表示していることと、ジェンキンズがすべてのテストで同じように何か同じものを表示すると思います(これらのツールがどのように取得するのかわかりません)。私はどういうわけか非静的方法で自分の名前を作成できますか?