I want to run single test class from command line using Maven and TestNG
Things that doesn't work:
mvn -Dtest=ClassName test
I have defined groups in pom.xml, and this class isn't in one of those groups. So it got excluded on those grounds.
mvn -Dgroups=skipped-group test
mvn -Dsurefire.groups=skipped-group test
when config is
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<groups>functest</groups>
</configuration>
</plugin>
Parameters work fine in there are no groups defined in pom.xml.
Similarly, when surefire is configured with
<configuration>
<includes>
<include>**/*UnitTest.java</include>
</includes>
</configuration>
I can add another test with -Dtest
parameter, but cannot add group. In any combination, I can narrow down tests to be executed with groups, but not expand them.
What's wrong with my configuration? Is there a way to run a single test or group outside of those defined in pom.xml?
Tried on Ubuntu 10.04 with Maven 2.2.1, TestNG 5.14.6 and Surefire 2.7.1
The Maven surefire plugin provides a “test” parameter that we can use to specify test classes or methods we want to execute. If we want to execute a single test class, we can execute the command: mvn test -Dtest=”TestClassName”.
During development, you may run a single test class repeatedly. To run this through Maven, set the test property to a specific test case. The value for the test parameter is the name of the test class (without the extension; we'll strip off the extension if you accidentally provide one).
Groups in Groups Step 1: Open the Eclipse. Step 2: We create a java project named as "Groups_in_Groups". Step 3: Now we create a testng. xml file where we configure the above class.
As I've explained in question, any mention of groups either in pom.xml or on command line resulted in reduction of executed tests count. Only way I've managed to avoid this is by using mavens profiles like this:
<profiles>
<profile>
<id>test-slow</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>slow</groups>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
and then running tests with
mvn -P test-slow test
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