Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I exclude a specific testng test group via maven?

Tags:

java

maven

testng

 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

like image 994
Damo Avatar asked Oct 20 '25 11:10

Damo


2 Answers

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

like image 171
Vladimir L. Avatar answered Oct 23 '25 01:10

Vladimir L.


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.

like image 43
Krishnan Mahadevan Avatar answered Oct 23 '25 01:10

Krishnan Mahadevan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!