Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running TestNg suite multiple times

Tags:

java

testng

I have say N number of test classes and I have one test suite say testing.xml which can run all those N tests , how to run testing.xml that is test suite multiple times ? Please help me out how to programatically run it multiple times

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite1">
<test name="exampletest1">
<classes>
       <class name="tester.NewTest1" />
    </classes>
  </test>

  <test name="exampletest2">
    <classes>
       <class name="tester.NewTest2" />
    </classes>
  </test>

</suite>    
like image 996
Akshay Bhat Avatar asked Jul 18 '16 08:07

Akshay Bhat


People also ask

How do you run a test suite multiple times in TestNG?

You cannot do it from the xml, but in the @Test annotation - you can add a invocationCount attribute with the number of times you want to run it. It would come out as those many tests run in the report.

How do you run a single test case multiple times?

To run a single test case numerous times and that too in parallel, we can use an additional attribute of @Test annotation, threadPoolSize. Below is the sample code where we used both invocationCount and the threadPoolSize attribute. Now, after running the same XML file, five test case instances will run in parallel.

Can we have more than one suite in TestNG?

Yes, use a @Factory and create two instances of your test class, each with a different parameter.

Can multiple TestNG XML files run from a single XML file?

Now you can execute the individual xml files simply that right click on xml file and run as testng suite. But if you have multiple files then you need to put those xml files in a separate xml file and need to execute the same way as right click on xml and run as testng suite.


1 Answers

Here try this, you can modify this for whatever n times you want

for(int i=0;i<3;i++)
        {
            List<String> suites = new ArrayList<String>();
            suites.add("testng.xml"); //path of .xml file to be run-provide complete path

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

            tng.run(); //run test suite
        }
like image 120
Monk Avatar answered Oct 11 '22 08:10

Monk