Installation Of TestNG
Before we start learning Installation of TestNG, Let’s explore little about what is TestNG?
In simple words its Testing New Generation framework developed by Cedric Beust with new functionalities over Junit and Nunit.
It is a testing framework which can be used for unit, integration, end-to-end, functional testing.
It is used by developers to write unit level testcases as well as by automation engineers using selenium to write testcases.
It is very powerful tool which gives lot of options and features to design test cases to generate reports.
Purpose: Design Testcases in a systematic way. One can drive testcases with the help of TestNG framework.
It is an Open source free tool and available in the form of JAR file. It is only used with Java.
This is also called TDD framework: Test Driven Development (Along with development of code we can design test cases in Agile Methodology)
Advantages / Features
· Design Test cases in systematic way.
· Reporting Feature provides a detailed HTML report of every successful, failed or skipped test
· Annotation feature allows developers to handle exceptions and understand the code easily.
· Parallel testing assists testers in running multiple test cases with added benefit of CI/CD integration
· Flexible runtime configuration
· Dependencies can be defined
· Test cases can be grouped together or prioritized easily.
· Data provider
Let’s see different ways to install a TestNG
1) Install the plugin for IDE(Eclipse)
eclipse IDE -- Help – Eclipse Marketplace
2) Install the TestNG libraries inside the project
A) Maven Project
B) Normal Java Project
Make sure you have got the right version of Eclipse software installed. (Eclipse version 4.2 and above)
1. Installation of TestNG in Eclipse IDE through Eclipse Marketplace
Once Eclipse is launched, Click on Help and then Eclipse Marketplace
A new window would open up where type “TestNG” in the find text box and Click on the Go button
You will see the search results with TestNG at the top. Click on the install button next to it.
(you will see installed button if TestNG is already installed)
Accept Apace License Agreement and click “Finish”.
It will ask to restart Eclipse. Click Yes to restart Eclipse and it will be launched again.
Once Eclipse is launched, you can add TestNG libraries in the project.
Right click on particular project >> Properties >> Java Build Path >> Click “Add library”
New Window for Add library will open >> Select TestNG >> Click next
Click on Finish and TestNG will be added along with other JAR files
Once TestNG is added, Click TestNG and click apply. So it will update the project.
2. A) Installation of TestNG library in Maven Project
Once Eclipse is launched. Click File Tab >> New Project >> Select Maven Project. Create a Simple maven project by clicking Finish. This will create a project in File explorer with structure having POM.xml.
What is Maven POM.xml: -
Maven pom.xml file POM is an acronym for Project Object Model. The pom.xml file contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc. Maven reads the pom.xml file, then executes the goal.
The actual format of POM.xml after creating Maven Project is given below. We have to add TestNG dependencies in the file by adding dependency tag in the file first. To add TestNG dependency in that tag, follow the following steps:
· Search Maven repository in google (mvnrepository.com)
· Once repository website is open, Search TestNG in search box and you will get all related results.
· Select TestNG from org.tetsng
· Select recent stable version of TestNG (I selected 7.6.1 latest stable)
· Once you select the version, you will get dependency. Copy that in your POM.xml and Save you project so project will get build and libraries will get added in your project.
· If you want to check added libraries , Expand your project and check maven dependencies folder which is shown as below in the respective images.
Simple Maven Project POM.xml before adding any dependency
Latest stable version of TestNG
POM.xml after adding TestNG dependency.
TestNG jar added in your project.
2. B) Installation of TestNG library in Simple Java Project
At this point you all must be aware of creating simple Java project, still for those who do not remember.
Just follow simple steps:
Open the Eclipse >> File tab >> New Project >> Project Name “TestNGtrial”
(You can use any other name for your project)
Next step is to create folder in order to store jar file of TestNG or any other jar file. It is not a rule but must be followed to maintain standard format.
Download jar file so that we can use it in the project .
Go to mvnrepository and search for TestNG. Select latest stable version and you will find jar files under Files. The same procedure which you use to find dependency.
Once the file gets downloaded, copy jar file to resources folder.
Now your project structure will have a TestNG jar file in resources folder which we can use it .
Right Click jar file and Go to “Build Path” >> “Add Build Path” This will make another section with name “referenced libraries” which will make TestNG jar to be used as reference in this particular project.
I hope you are now clear with different ways for Installing TestNG in Eclipse. Thank You.