Getting started with TestNG in Eclipse

In this blogpost, we will see how to configure how to a TestNG project in Eclipse IDE, and run a simple TestNG test case.

If you have not installed TestNG plugin in Eclipse IDE, visit Installation of TestNG in Eclipse IDE.

Step 1 : Create a Java project in Eclipse

Open Eclipse IDE.

Go to File -> New -> Java Project, and finish the process by giving project name and selecting JRE version .

For more information on this, visit this link.

Step 2 : Add TestNG library to build path of the project

Once after creating a Java project, we need to add the TestNG library to the build path of the project in order to utilize TestNG capabilities.

In order to add the library to build path, follow below steps

Right click on the project -> Build Path -> Configure build Path

TestNG_Create_Simple_TestNG_Project.png

After clicking on the Configure Build Path button, a dialog box for configuring project properties will be prompted. Click on Add Library button from the dialog box.

 

TestNG_Create_Simple_TestNG_Project_Add_Library.png

After clicking Add Library button, the wizard for adding library will be prompted, select TestNG from the list, click Next/ Finish button.

TestNG_Create_Simple_TestNG_Project_Add_Library2.png

Once after clicking Next/ Finish button, TestNG would have been added in the Libraries, and you would be able to see it in Project Explorer, as shown below.

TestNG_Create_Simple_TestNG_Project_Explorer_Library_added

Step 3 : Create a TestNG class

Go to src folder of the Eclipse project, and follow the below steps.

Right click on src folder -> New -> Other -> TestNG class

You will be able to see a window as shown below. Click Next to continue.
Create-testng-class-in-eclipse

Eclipse provides the options to  customize out TestNG class during creation. Here, we can select the annotations as per our needs, and click Finish.

 

Create-testng-class-in-eclipse2

On clicking Finish, the test class will be created with all the selected annotations methods in the previous step.

Step 4 : Run TestNG class in Eclipse

Now, it is time to run the test class created in previous step. Follow below series of steps to run the TestNG class.

Right click on TestNG class -> Run As -> TestNG Test

run-testng-testcase.png

You will be able to see result of the run as below.

result-of-testng-run.PNG

That is all from this blogpost. Hope it helps you!

Cheers 🙂

 

Advertisements

#create-a-testng-project-in-eclipse, #getting-started-with-testng