我想为runTestSuite()方法中调用的每个输入发送baseTestBeforeTest()方法生成的输入(这将是单元测试方法),换句话说:我如何使用循环为了在循环的每次迭代中向我的测试方法发送不同的输出?
@BeforeTest
public void baseTestBeforeTest() throws Exception {
String cageInstanceIp = Configuration.prop.getProperty("suite.pusher.defaultParams.cageInstanceIp");
addingAllFilesToList();
int size = this.files.size();
System.out.println("number of session to be run are: " + size);
for(int i=0;i<size;i++){
System.out.println("-------------------------------------------------------------------------------------------------------------------------");
System.out.println("running test for the following json input file: " + this.files.get(i));
System.out.println("-------------------------------------------------------------------------------------------------------------------------");
this.list=this.runHelperForTestsPreparationMethods.runHelperPreparation(this.files.get(i), this.list);
if(i==size-1){
isLast=true;
}
runTestSuite();
}
}
这是runTestSuite()方法:
@Test
public void runTestSuite() throws Exception {
this.runHelperForTestsPreparationMethods.testCompareJsonPercentage(this.isLast);
testCompareJsonPercentage(isLast);
}
但我得到的是,在for循环完成并按预期为每个输入运行测试后,它再次立即运行testTestSuite()方法作为TestNG逻辑的一部分,我希望能够不能面对这个问题,并为每个输入运行基本测试和测试(单元测试)。
我搜索网络寻求解决方案,但没有发现任何......
答案 0 :(得分:0)
我所做的是将baseTestBeforeTest()方法声明为测试本身,并从runTestSuite()方法中删除测试注释,该方法将作为baseTestBeforeTest()测试用例的一部分。
这一切都很有意义,测试运行应该如此。