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
Best Answer
I didn't test with TestNG 5.12.1 but I can say that running a single test using the
test
parameter and tests from groups using thegroups
parameter works with TestNG 5.14.2 (and surefire 2.6) (groups
doesn't work in TestNG 5.14)Here is the
pom.xml
I'm using:With a simple
AppTest
as follow:Both
and
produce the expected result.