I have a testng case with following annotation -
@Test(groups="groupA", dataProvider="DataSet1")
But when I trigger following maven command it does not execute the test -
mvn test -Dgroups=groupA
All I see in console is this -
...
...
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ abc-proj ---
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.733 sec -      in TestSuite
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
But when I simply run mvn test it executes the test. Not sure why it is behaving like this. I am using Surefire plugin version 2.19.1 and testng version 6.9.9. Any help will be appreciated.
EDIT I am not using testng.xml and just out of curiosity I tried same thing in a small project -> it works. In that project I created a sample class -
import org.testng.annotations.Test;
public class SampleTest {
    @Test(groups = "groupA")
    public void testA() {
        System.out.println("Inside A");
    }
    @Test(groups = "groupB")
    public void testB() {
        System.out.println("Inside B");
    }
}
And the pom.xml is -
... 
<properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.9</version>
        </dependency>
    </dependencies>
</project>
Here the command mvn test -Dgroups=groupA works fine!
EDIT2 When I removed the dataProvider annotation I noticed some different result, console now says - 
Tests run: 1, Failures: 0, Errors: 0, Skipped: 1
You probably need to group your tests into surefire configuration to do that:-
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
      <groups>ABC,XYZ</groups>
    </configuration>
</plugin>
and then execute
mvn test -Dgroups=ABC
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