4
 mvn test -Dgroups=group3,group2

Will execute groups3 and groups2 - as per Can I run a specific testng test group via maven?

I want to run all test that are not in a group. Is this possible through maven? E.g. I want to run all test that are not in group3.

"pseudo maven command" mvn test -Dgroups!=group3

Damo
  • 1,449
  • 3
  • 16
  • 29
  • 1
    Possible duplicate: https://stackoverflow.com/questions/9123075/maven-how-can-i-skip-test-in-some-projects-via-command-line-options – Timothy Truckle Jul 09 '17 at 21:01

2 Answers2

5

According to official TestNG documentation, see "Command Line Parameters" table here http://testng.org/doc/documentation-main.html#running-testng , it should be possible with:

$ mvn test -Dexcludegroups=group3

However, for greater flexibility I would recommend to use test suite configuration file (aka testng.xml), the location of which can be configured via <suiteXmlFile> property of surefire-plugin, see: http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html

This will allow to take a full control over groups inclusion/exclusion, see: http://testng.org/doc/documentation-main.html#exclusions

Vladimir L.
  • 1,116
  • 14
  • 23
  • 6
    When you run it with Maven with Surefire, the parameter you need is `-DexcludedGroups=groupfoo`. See http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html – Macil Mar 10 '18 at 00:11
1

Yes you can do that using a beanshell in TestNG.

You create a suite xml file and define a beanshell as below :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="false">
    <test name="Test">
        <method-selectors>
            <method-selector>
                <script language="beanshell">
                <![CDATA[whatGroup = System.getProperty("groupToRun");
                !Arrays.asList(testngMethod.getGroups()).contains(whatGroup);
                ]]>
                </script>
            </method-selector>
        </method-selectors>
        <classes>
            <class name="organized.chaos.GroupsPlayGround" />
        </classes>
    </test> <!-- Test -->
</suite> <!-- Suite -->

This would basically cause TestNG to look for all tests that don't belong to the group which was passed via the JVM argument groupToRun

I have explained about this in my blog here.

You can also find more information about this on the Official TestNG documentation here.

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66