29

I have several testng test groups, e.g. group1,group2,group3... These are defined in my pom.xml and all get run when I execute "mvn test". What do I need to run to only execute one group without having to modify the groups configured in the pom.xml.

i.e mvn test group2 mvn test group1 mvn test group3

Tom Eustace
  • 293
  • 1
  • 3
  • 4

4 Answers4

53

Try

mvn test -Dgroups=group3,group2
ThisaruG
  • 3,222
  • 7
  • 38
  • 60
Eugene Kuleshov
  • 31,461
  • 5
  • 66
  • 67
7

I came across this question while looking how to disable particular test group and Radadiya's answer confused me a bit.

To run particular groups use this, as mentioned by Eugene Kuleshov. docs

mvn test -Dgroups=group1,group2

But to exclude some group, use this (note excluded vs exclude). docs .

mvn test -DexcludedGroups=group3,group4
dan1st
  • 12,568
  • 8
  • 34
  • 67
Mikalai Parafeniuk
  • 1,328
  • 15
  • 10
2

You can include and exclude specific group during maven test execution.

(1) Include Specific Groups

mvn clean test -DincludeGroups=TestGroup1,TestGroup2

(2) Exclude Specific Groups

mvn clean test -DexcludeGroups=TestGroup3,TestGroup4
Radadiya Nikunj
  • 988
  • 11
  • 10
0

You can also run tests that have a combination of groups. This will execute tests that are marked both with "group1" and "group2":

mvn test -Dgroups=group1&group2