top of page

TestNG Test

How To Write First Test In TestNG ?

I hope you have installed the testNG plugin in your IDE as explained in previous article. So let's start to write a test in testNG.

Add TestNG Library in the Project

Now create a java project in your IDE and add essential jars in the project as per requirement.

After this,right-click on the project and go to the 'Build Path' then select 'Configue Build Path...' .


Under the 'Libraries' section select 'classpath' and then click on 'Add library...' .

Now here select 'TestNG' then proceed with 'Next' and 'Finish' and then 'Apply and Close' .


If it would be done successfully,you will see 'TestNG' library within your project.

Create a TestNG Class

For creating a class,a good approach is to create a package first.So,I create a package as 'testNGexamples'.

Now I will create the classes within it.

Follow the steps to create a testNG class :

Right-click on the package select 'create TestNG class' under 'TestNG' option.

A pop-up window will be opened,write class name and select annotaions(optional) then 'Finish' .

TestNG class has been created now.Write your test here.

An Example of Test In TestNG =>

package testNGexamples;

import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;

public class SimpleTest {


//This is the Test
  public void firstTest() {
     System.out.println("Test Is Executing ...");


 //This will execute before class
  public void beforeClass() {
     System.out.println("Test starts :");


 //This will execute after class
  public void afterClass() {
     System.out.println("Test ends :");




Output :
















Refer next page TestNG Test Suite

bottom of page