[ACCEPTED]-Running single test class or group with Surefire and TestNG-surefire

Accepted answer
Score: 11

I didn't test with TestNG 5.12.1 but I can 6 say that running a single test using the 5 test parameter and tests from groups using the 4 groups parameter works with TestNG 5.14.2 (and 3 surefire 2.6) (groups doesn't work in TestNG 5.14)

Here 2 is the pom.xml I'm using:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

With a simple AppTest as follow:

import org.testng.annotations.*;

public class AppTest {

 public void setUp() {
   // code that will be invoked when this test is instantiated

 @Test(groups = { "fast" })
 public void aFastTest() {
   System.out.println("Fast test");

 @Test(groups = { "slow" })
 public void aSlowTest() {
    System.out.println("Slow test");


Both 1

$ mvn test -Dtest=AppTest


$ mvn test -Dgroups=slow

produce the expected result.

Score: 4

As I've explained in question, any mention 5 of groups either in pom.xml or on command 4 line resulted in reduction of executed tests 3 count. Only way I've managed to avoid this 2 is by using mavens profiles like this:


and 1 then running tests with

mvn -P test-slow test
Score: 0

I would suggest to try something like

mvn test -Dincludes=rs/magrathea/TestClassName

although 1 I haven't tested this myself.

Score: 0

In order to run a single test you need the 11 following from official documentation

mvn -Dtest=MyFirstTest test

or 10

mvn -Dtest=MyFirstTest,MySecondTest test

This 9 is tested (and working) on maven 3.

Then 8 you can avoid using the profiles. I had 7 the same problem as I needed to run load 6 test in isolation and using profiler in 5 parallel to get the real figures.

Note: Not 4 sure why but make sure that the switches 3 come before the phase i.e. "-Dtest=MyFirstTest" before 2 "test" otherwise it is not working 1 (Mac OSX)

More Related questions