top of page

TestNG Tutorial

TestNG Test

How To Write First Test In TestNG ?

I hope you have installed the testNG plugin in your IDE as explained in previous articles. So let's start writing 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 a 'TestNG' library within your project. ​ ​
​ ​ ​ Create a TestNG Class For creating a class, a good approach is to create a package first. So, I will create a package as 'testNGexamples'. Now I will create some classes within it. ​ Follow these steps to create a testNG class : Right-click on the testNGexamples package, select 'create TestNG class' under 'TestNG' option. ​

A pop-up window will be opened, write class name there 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 { @Test //This is the Test public void firstTest() { System.out.println("Test Is Executing ..."); } @BeforeClass //This will execute before class public void beforeClass() { System.out.println("Test starts :"); } ​ @AfterClass //This will execute after class public void afterClass() { System.out.println("Test ends :"); } }


Output :


Refer next page TestNG Test Suite
bottom of page