I am using Surefire Plugin, and I have a suite like this:
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/suites/testng1.xml</suiteXmlFile>
<suiteXmlFile>src/test/resources/suites/testng2.xml</suiteXmlFile>
</suiteXmlFiles>
If I execute this command:
mvn clean test
then both xml files are executed. Now I want to run only testng2.xml
, so I specify its path in this command:
mvn clean test -Dsurefire.suiteXmlFiles=/src/test/resources/suites/testng2.xml
but it doesn't work, because both testng1.xml and testng2.xml are again executed.
Am I missing something? I use Maven v3.5. Thanks
One way to do it:
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
And in the command line:
mvn test -DsuiteXmlFile=src/test/resources/suites/testng2.xml
This code 'replaces' the variable ${suiteXmlFile} with the value provided.
Now if you want to have a default suite in your pom.xml which is executed when you do mvn test
, but is overriden if you do mvn test executeAnotherSuiteInsteadOfDefault
, check this answer: https://stackoverflow.com/a/13829933/5494070.