Reputation: 224
I want to run a specific test suite from command line using maven command. I am using TestNg framework.
My pom has the following configuration setup:
<profiles>
<profile>
<id>selenium-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<!--
<parallel>methods</parallel>
<threadCount>6</threadCount>
-->
<!-- <suiteXmlFiles>
<suiteXmlFile>src/test/java/com/kanban/testng/factory.xml</suiteXmlFile>
</suiteXmlFiles> -->
<suiteXmlFiles>
<suiteXmlFile>${suiteFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
on the command line I am running:
mvn clean test -DsuiteFile=src/test/java/com/kanban/testng/factory.xml
This should ideally run only factory.xml test suite, but its running all the tests in the project.
Can any one suggest if I am missing something.
Upvotes: 1
Views: 2297
Reputation: 224
Thanks for the reply Vlad:
Here is the solution that worked for me:
go to the pom directory where your root pom is then execute: mvn test -DsuiteFile="src/test/java/com/kanban/testng/factory.xml" -P'selenium-tests'
where content in the double quotes is the path to the test suite that has to be executed and content in single quotes is the profile id of your maven-surefire-plugin
Upvotes: 2
Reputation: 1358
Probably Maven picks up anything with the word "Test" in the class name.
That is probably because of the Maven Surefire Plugin's default inclusion patterns:
By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:
"**/Test*.java" - includes all of its subdirectories and all java filenames that start with "Test". "**/*Test.java" - includes all of its subdirectories and all java filenames that end with "Test". "**/*TestCase.java" - includes all of its subdirectories and all java filenames that end with "TestCase".
And, as you know, "Suite XML Files configuration will override the includes and excludes patterns and run all tests in the suite files."
I cannot tell for sure, but it looks like there are some troubles with reading the factory.xml file (file is not found, parsing, encoding issue, etc) and Surefire falls back to the inclusion/exclusion policies.
You may do a little test to prove this. Add 'includes' and/or 'excludes' sections inside 'configuration' and exclude all classes except random one. If that random class is run, then the 'suiteXmlFiles' is simply ignored.
Hope this will narrow down the scope.
(copied my answer from the similar topic)
And don't forget to specify the profile -Pselenium-tests
Upvotes: 1