I see a lot of posts on here about running a TestNG suite using Maven surefire plugin. The examples say to add this to the pom:
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${testSuite}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
And then this to the command line:
mvn test -DtestSuite=myCustomSuite.xml
My problem with this is that it ties you to using the TestNG suite... For example, if I want to run with groups like this:
mvn test -Dgroups=myGroup
I get this error:
maven-surefire-plugin:2.18.1:test failed: testSuiteXmlFiles0 has null value
I want to be able to run, from command line, passing in either a suite path or groups.
Instead of using your surefire configuration with a property, you can:
mvn test -DtestSuite=myCustomSuite.xml
by mvn test -Dsurefire.suiteXmlFiles=myCustomSuite.xml
. See Surefire documentation
mvn test -Dgroups=myGroup
.As the surefire configuration will be removed, the error testSuiteXmlFiles0 has null value
won't be present with the -Dgroup
option.
You can also use maven profiles which will configure surefire plugin depending on which property you pass to maven.
<profiles>
<profile>
<id>suite</id>
<activation>
<property>
<name>testSuite</name>
</property>
</activation>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${testSuite}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</profile>
</profiles>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With