简体   繁体   中英

TestNG @Test(invocationCount = 20) to a Class with @Test(DataProvider=“someList”) to a Method

I have a TestNG test Suit for a JAVA Project and, In there I have a

@Test(DataProvider="ListOfObjects") annotated Method. Which provides method with around 20 rows of data.( Hence the method runs 20 times.) Now, I want to run this class for 2hrs (part of SOAK related test.) On average the Class takes around 10 mins for single run. So I am thinking or running the whole class for 12 times, and thus thinking of using @Test(invocationCount = 20) on the Class itself . Any Better Ideas ?

You could extract the test in a method, then create a test method with a reasonably high invocation count. In that test method, compare the time with a variable holding the timestamp of the first run and if it has run for more than 20 minutes skip the test.

Found an Embarrassingly simple solution: Repeating the whole Test Suit as follows

@Test
public void RepeatTestSuite() {
    long startTime = new Date().getTime();
    while(!isTestFinished(startTime)) {

          List<String> suites = new ArrayList<String>();
             suites.add("./SOAK_all41.xml"); //path of .xml file to be run-provide complete path

             TestNG tng = new TestNG();
             tng.setTestSuites(suites);

             tng.run(); //run test suite
        }

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