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
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
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.
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