Running single test class or group with Surefire and TestNG

2,662 views
Skip to first unread message

Luka Stojanovic

unread,
Jan 17, 2011, 3:04:25 PM1/17/11
to testng...@googlegroups.com

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


--
Luka Stojanovic
lu...@vast.com
Platform Engineering

Krishnan Mahadevan

unread,
Jan 18, 2011, 3:39:39 AM1/18/11
to testng...@googlegroups.com
Luka,
For running a single test class from command line using Maven and TestNG, the following worked for me:

mvn -Dtest=ClassName test

provided you have testNG dependency scope defined as compile and not as test

<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>5.14</version>
    <scope>compile</scope>
</dependency>

Hope that helps.
- Krishnan


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.


Luka Stojanovic

unread,
Jan 18, 2011, 9:35:00 AM1/18/11
to testng...@googlegroups.com

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 maven's 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

Reply all
Reply to author
Forward
0 new messages