Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Hello Ninjas! In this article, we will learn about the Integration of Maven with TestNG. We are going to start with understanding what maven and TestNG are and why there is a need to integrate Maven with TestNG.
About Maven
Maven is an open-source build automation tool developed by Apache Group for better project management. It is written in Java to create projects in languages such as C#, Scala, Ruby, etc. Maven helps developers to build, publish and develop projects, dependencies, and documentation.
About TestNG
It is a testing framework that is designed for the Java programming language. TestNG covers many test categories with powerful and user-friendly functions such as unit, functional, end-to-end, integration, etc.
Basic Terminologies
Maven Surefire Plugin: Maven Surefire plugin is used to execute an application's unit tests during the build lifecycle test phase.
Maven Central Repository is a space where all the libraries and plugins are stored.
POM (Project Object Model): Project Object Model is an XML file and a basic work unit in Maven. It carries information about the project and the configuration details used by Maven during the process.
Before proceeding with the setup procedure, let us look at why there is a need to integrate Maven with TestNG -
We can not select a specific test suite to execute from the list of available suites without integrating Maven and TestNG.
We can not manage our dependencies in TestNG without integrating it with Maven.
Step 1: Choose a POM.xml file from the maven Project < Right-click < Maven < Add plugin.
Step 2: The “Add Plugin” window will be displayed
Steps to enter the plugin details -
Click here and look for the “Using TestNG” option on the left side of the window.
Select the XML code displayed under the “Using Suite XML File” header < Enter Group ID, Artifact ID, and Version details in the “Add Plugin” window using the XML code snippet given below
Click Okay
Now add
groupId = org. Maven.plugins
artifactId = maven-surefire-plugin
version = 3.0.0-M7
Step 3: Click Okay. The plugin is now added to the selected pom.xml file.
Execute a Test Suite using Maven Surefire Plugin.
Right-click on your java program file in the package explorer and select TestNG > Convert to TestNG.
In the Refactoring window, click on “Next.”
Now click on “Finish”. It will create a testng.xml file.
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="javaPackageName.ClassName"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
Now add the following line in the pom.xml file between </version> and </plugin>.