How to exclude TestNG Groups from Maven? Last Updated : 27 Sep, 2024 Comments Improve Suggest changes Like Article Like Report To exclude specific TestNG groups from execution when running tests through Maven, you can configure the maven-surefire-plugin in the Maven pom.xml file. The Surefire plugin is responsible for running the unit tests during the build process, and it supports excluding certain groups from being executed.Approach to Exclude TestNG Groups from MavenFollowing are the steps to exclude TestNG groups from Maven:Create a Maven Project: First, create a maven project on any ide like Eclipse or IntelliJ Create a class: Create a java class (eg:TestClass1) under src/test/java in that Maven projectAdd Test Methods: Add Test Methods in each class using @test annotation add a group attribute to each method and write your logic in that test method.Configure POM.xml file: In the pom.xml file, configure the maven-surefire-plugin to exclude specific groups using the <excludedGroups> tag. This tag allows you to specify which groups should be excluded during test execution.Run the project: To run the project. Open the terminal and write the mvn test, this will exclude the group.Example CodeTestClass1.java Java package TestNG.SeleniumJava; import org.testng.annotations.Test; public class TestClass1 { @Test(groups = "group1") public void testMethod1() { System.out.println("TestClass1 - testMethod1 from group1"); } @Test(groups = "group2") public void testMethod2() { System.out.println("TestClass1 - testMethod2 from group2"); } } pom.xml XML <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>TestNG</groupId> <artifactId>SeleniumJava</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>SeleniumJava</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M5</version> <configuration> <excludedGroups>group2</excludedGroups> </configuration> </plugin> </plugins> </build> <dependencies> <!-- https://mvnrepository.com/artifact/org.testng/testng --> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.7.1</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project> Output:In order to run the project. Open the terminal and write the following command, this will exclude the group.mvn testConclusionBy configuring the maven-surefire-plugin in the pom.xml file and using the <excludedGroups> tag, you can easily exclude specific TestNG groups from being executed during the Maven build process. This allows for greater flexibility in controlling which tests are run, especially in scenarios where certain tests are not relevant or are under development. Comment More infoAdvertise with us Next Article How to exclude TestNG Groups from Maven? C cyrust8t7y Follow Improve Article Tags : Software Testing Testing Tools Maven TestNG Similar Reads How to run TestNG from command line? Running TestNG from the command line is a powerful technique for managing your automated tests efficiently. TestNG is a popular testing framework that provides various features for running and configuring tests. While IDE-based execution is common, using the command line offers greater flexibility a 4 min read How to call testng.xml file from pom.xml in Maven? Maven is a tool that is widely used for automation whenever developers work on Java projects. apart from the Java language, the Maven software supports other projects that are written in C#, Ruby, etc. The Maven project is controlled and hosted by the famous Apache software foundation.Table of Conte 4 min read How to pass java code a parameter from Maven for testing? Maven is one of the most commonly used tools in Java projects for build automation, allowing the developer to manage the dependency of their project and many other operations, like compiling codes or running tests. Sometimes, you may want to pass some parameters from Maven to the Java code, so you c 3 min read How to get current class name from BeforeClass in TestNG? In TestNG, the @BeforeClass annotation is used to execute a method before any of the test methods in the current class are run. Sometimes, you may want to retrieve the current class name inside a @BeforeClass method for logging, debugging, or other purposes. Java provides several ways to access the 2 min read How to Run a testng.xml File From Batch for a Maven Project? In a Maven project, testng.xml is a configuration file used by TestNG to define and organize which tests to run. To automate the process of running these tests, you can use a batch file. A batch file is a simple script that automates command-line tasks.Why Use a Batch File?A batch file allows you to 3 min read Like