TestNG有条件地多次运行测试



我想在Table.getTables((第一次运行下面的测试两次(或更多次(时返回应该包含20个项目的表列表,但当第二次运行测试时,它不会返回任何项目。所以,我想检查它是否是第一次运行,然后检查它是否有20个项目,如果是第二次运行,我想查看它是否不包含任何项目。我认为invocationCount对我不起作用。请参阅下文。感谢

Java 8和TestNG 6.14。


//Run this test twice 
@Test
public void repeatTest() {
List<String> tables = Table.getTables();
//if it is 1st run then check this
Assert.assertEquals(tables.size(), 20); 
//if it is second run then check this 
Assert.assertEquals(tables.size(), 0); 
}

您只需调用两次:

@Test
public void repeatTest() {
List<String> firstList = Table.getTables();
//if it is 1st run then check this
Assert.assertEquals(firstList.size(), 20); 
List<String> secondList = Table.getTables();
//if it is second run then check this 
Assert.assertEquals(secondList.size(), 0); 
}

最新更新