I need to run multiple test suites in parallel. One of the approaches being, to create a suite file as below -
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="AllTests" verbose="8"> <suite-files> <suite-file path="./Suite1.xml"></suite-file> <suite-file path="./Suite2.xml"></suite-file> </suite-files> </suite> Create a class as below -
import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.List; import javax.xml.parsers.ParserConfigurationException; import org.testng.xml.Parser; import org.testng.xml.XmlSuite; import org.testng.TestNG; import org.xml.sax.SAXException; public class RunSuitesInParallel{ public static void main(String[] args) throws FileNotFoundException, ParserConfigurationException, SAXException, IOException { TestNG testng = new TestNG(); testng.setXmlSuites((List <XmlSuite>)(new Parser("src"+File.separator+"test"+File.separator+"resources"+File.separator+"xml_Suites"+File.separator+"AllTests.xml").parse())); testng.setSuiteThreadPoolSize(2); testng.run(); } } I am able to achieve the goal with the above when I run it from Eclipse IDE. How do I run this from a maven command line?
Snippet of POM.xml -
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.14.1</version> <configuration> <include>com/shn/test/*Tests.class</include> <suiteXmlFiles> <!-- <suiteXmlFile>src/test/resources/TestNG.xml</suiteXmlFile> --> <suiteXmlFile>${tests}</suiteXmlFile> </suiteXmlFiles> <testFailureIgnore>true</testFailureIgnore> </configuration> </plugin> Currently to execute any given XML I use -
mvn -Dtests=AllTests.xml test