Spread the love

Learn How To Install TestNG for IDEs Quickly

Spread the love

How To Install TestNG?

System requirements for TestNG

As per TestNG site below are the system requirements:

  • JDK- 1.7 or higher.
  • There is no restriction on Memory, Disk space or Operating system.

How to Download TestNG?

TestNg is available in different forms. This page tells about different ways to download a TestNG. However, I suggest always to download from MVN Repository.

Downloading TestNG can be performed in the following manners too:

  • Using an Eclipse Market place
  • Using the command line
  • Using IntelliJ plugins
  • Using ANT
  • Using Maven

What is TestNG Maven dependency?

On the Maven repository, TestNg libraries are also kept. We can configure and define the maven dependency to include TestNG into our project.

<dependency>
	<groupId>org.testng</groupId>
	<artifactId>testng</artifactId>
	<version>7.1.0</version>
	<scope>test</scope>
</dependency>

How to download TestNG in Eclipse as plugins?

  • Step-1 Create a java project in Eclipse.
  • Step-2 Click on Help | Select Eclipse Market place from the eclipse drop-down menu.
Open Market place in Eclipse
How to open Market place in Eclipse
  • In the find textbox, we need to put TestNG and search
Put TestNG in Find textbox
Put TestNG in Find textbox
  • Once we find TestNG we need to install
Install TestNG
Install TestNG
  • Make sure the checkbox next to the URL is checked and click Next.
READ  Learn Quickly on How to Work With TestNG XML
Select all checkboxes in TestNG
Select all checkboxes in TestNG
  • The eclipse will then guide you through the process.

How to use drag and drop TestNG in Eclipse?

We need to open TestNG for Eclipse. Then drag and drop the TestNG to Eclipse.

How to install TestNG via new software?

  • We need to select Help / Install New Software…
Install New Software for TestNG
Install New Software for TestNG
Click on Add button
Click on Add button
  • We need to provide a name as TestNG and we need to click on the Add button.
READ  Learn Annotations in TestNG in an Easy Effective and Quick Manner
Provide name as TestNG
Provide name as TestNG
  • The fetching bar will show the fetching operation.
  • We need to check the TestNG checkbox.
Select all checkboxes in TestNG
Select all checkboxes in TestNG
  • Make sure the checkbox next to the URL is checked and click Next.
  • The eclipse will then guide you through the process. Like License agreement checkbox etc.

For all the cases the Eclipse will restart to take effect.

How to Check if TestNG is properly installed in Eclipse?

To check if TestNG is properly installed in Eclipse, we need to navigate to Windows | Preferences | Select and Expand TestNG

Windows Preference to check TestNG installation
Windows Preference to check TestNG installation

How to configure TestNG?

This is applicable if we have downloaded the TestNG.jar.  Now before we proceed further, check path and classpath settings here. Initially, we need to verify if we have java installed in our machine.

Once we are satisfied, the similar way we need to set up the TestNG into path and classpath.

Operating SystemHow to set
WindowsSet the environment variable TestNG_HOME to TestNG’s download directory
LinuxExport TESTNG_HOME=/usr/local/TestNG
MacExport TESTNG_HOME=/Library/TestNG

Setup classpath for TestNG:

Operating SystemHow to set
WindowsSet the environment variable CLASSPATH to
%CLASSPATH%;%TESTNG_HOME%\testng-X.X.jar.
LinuxExport CLASSPATH=$CLASSPATH:$TESTNG_HOME/testng-x.x.jar.
MacExport CLASSPATH=$CLASSPATH:$TESTNG_HOME/testng-x.x.jar
READ  What is TestNG?

 

TestNG Structure

TestNG Structure
TestNG Structure

Configure TestNG with Eclipse

In Eclipse, we can configure TestNG in two different ways. They are as follows:

  1. Adding the TestNG jar to the Build path
  2. Using plugins available at the market place.

Adding the TestNG jar to the Build path

We need to create a java project in Eclipse. We will follow the below steps:

  • Go to File | New | Other. A window with multiple options will be shown as follows
Select Java Project in TestNG
Select Java Project in TestNG
  • Now enter a Project name for a Java project, let’s say TestProject, as shown in the following screenshot, and click on Finish:
Create New Java Project in TestNg
Create a New Java Project in TestNg
  • Go to Project | right-click and select Properties. Java Build Path on the left-hand side will be auto-selected.
Open Buildpath in java
Open Buildpath in java
  • Select the module and click on Add External Library option.
Add external jar
Add external jar
  • We need to select TestNg.jar we have downloaded previously.

Adding the TestNG via Library

Adding the TestNG jar to the Build path

We need to create a java project in Eclipse. We will follow the below steps:

  • Go to File | New | Other. A window with multiple options will be shown as follows
Select Java Project in TestNG
Select Java Project in TestNG
  • Now enter a Project name for a Java project, let’s say TestProject, as shown in the following screenshot, and click on Finish:
Create New Java Project in TestNg
Create a New Java Project in TestNg
  • Go to Project | right-click and select Properties. Java Build Path on the left-hand side will be auto-selected.
Open Buildpath in java
Open Buildpath in java
  • Click on the Libraries tab and click on the Add Library
Add TestNG Library
Add TestNG Library
  • Click on Next | Finish | Apply | Apply and Close

Test the TestNG setup

We need to write a simple test if TestNG is running successfully into our system.

READ  What is TestNG?

How to write TestNG test cases?

TestNG test creation is a four-step easy and clean process. They are as follows:

  • Write a test case that expresses the business logic that needs to be validated.
  • Insert TestNG notations in the code.
  • Add the necessary details of your test and configurations to the testng.xml
  • Execute the TestNG test.
READ  Learn How to Work on Groups in TestNG Effectively

How to write the first Test in Eclipse in TestNG?

  • We need to create a java project in Eclipse.
  • Add TestNG library or TestNG jar to our test.
  • Create a new package say com.com.test.
  • Now we need to right-click on the package we have just created.
  • We need to select New | Others | then we have to expand the TestNG to select TestNG Class.
Select TestNG class
Select TestNG class
  • We need to provide the details like below:
  • Source folder- We need to browse the folder structure via the Browse button and select the path to the src of the project.
  • Package name- we need to provide the package name. (It will mostly auto-populated).
  • Class name- We need to provide the class name.
  • Now we need to select the Annotations based on our requirements. They can be configured later as well.
  • Lastly, we can provide an optional XML suite as well.
  • Click on the Finish button.
sample TestNG class generation
sample TestNG class generation

The sample class file looks like below

package com.com.test;

import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.AfterSuite;

public class NewTest {
  @Test(dataProvider = "dp")
  public void f(Integer n, String s) {
  }
  @BeforeMethod
  public void beforeMethod() {
  System.out.println("Before Method");
  }
  

  @AfterMethod
  public void afterMethod() {
	  System.out.println("After Method");
  }


  @DataProvider
  public Object[][] dp() {
    return new Object[][] {
      new Object[] { 1, "a" },
      new Object[] { 2, "b" },
    };
  }
  @BeforeClass
  public void beforeClass() {
	  System.out.println("Before Class");
  }

  @AfterClass
  public void afterClass() {
	  System.out.println("After Class");
  }

  @BeforeTest
  public void beforeTest() {
	  System.out.println("Before Test");
  }

  @AfterTest
  public void afterTest() {
	  System.out.println("After Test");
  }

  @BeforeSuite
  public void beforeSuite() {
	  System.out.println("Before Suite");
  }

  @AfterSuite
  public void afterSuite() {
	  System.out.println("After suite");
  }

}




Spread the love
Animesh Chatterjeehttps://techtravelhub.com/
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

Related Articles

Learn How to Work on Groups in TestNG Effectively

What are the groups in TestNG? Groups concept in TestNG is a...

Comments

  1. […] How To Install TestNG? System requirements for TestNG As per TestNG site below are the system requirements: JDK- 1.7 or higher. There is no restriction on Memory, Disk space or Operating system. How to Download TestNG? TestNg is available in different forms. This page tells about different ways to download a TestNG. However, I suggest […] Source: https://www.techtravelhub.com/install-testng/ […]

  2. […] fromhttps://www.techtravelhub.com/install-testng/ […]

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Recent Posts

Learn Quickly About DevOps Tools in a Fast and Efficient Manner

Introduction to DevOps tools DevOps tools are a collection of...

How to Collaborate between Development and Operations Team Fast and Effectively

Collaborate between Development and Operations Teams are the key...

Learn How to Use Jacoco Java code Coverage

Introduction to Jacoco Jacoco provides a wide range of coverage(analysis...

EDITOR PICKS


Spread the love