简体   繁体   中英

TestNG run the test several times conditionally

I want to run the test below 2 times(or more) first time the Table.getTables() returns the list of tables which should contain 20 items, but when the tests runs second time it will not return any item. So, I want to check to see if it is first run then check to see if it has 20 items and if it is second run I want to check to see if it does not contain any item. I do not think invocationCount will work for me. Please see below. Thanks

Java 8 and 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); 
    }

You can just call it twice:

@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); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM