Create a simple Java project and install TestNG in Eclipse.

testng1

TestNG is the tool that provides platform to perform unit testing of your application. Mostly TestNG is used by developers to perform unit testing, but now a days TestNG is also widely used by software testers for white box testing.

TestNG generates the report that is very useful to analyze the application performances. Easy to debug and find the bugs. As a software tester I use TestNG to generate the report for the testing performed by selenium automation tool.

If you are developing your application using eclipse and want to perform unit testing, I suggest TestNG is the perfect tool.

There are two ways to install TestNG in eclipse.

  • Download standalone Jar files and add to eclipse.
  • Directly install TestNG in eclipse without downloading Jar files.

Here are the steps to install TestNG in eclipse-

Make sure you have downloaded the correct version of eclipse.

If not you can click on the link to download eclipse – Click Here

Follow the steps to create your first Java project in Eclipse:

1) Once downloaded and extracted the eclipse folder, open Eclipse folder and double click on the Eclipse.exe icon to start Eclipse.

sw3

2) Once Eclipse starts successfully will ask you to provide work location. You can provide work location or you can leave as it is to select Eclipse default work location.

ecl1

3) Click OK button to continue.

4) Go to File -> New -> Project and click on Project.

sw5

5) Click on Java Project and then click on Next button.

sw6

6) Provide the project name and click on Next.

sw7

7) Finally click on Finish to add the project in Eclipse.

sw8

8) In this project, Class will not be added so lets add the class so that you could write your code.

9) Right click on src under project shown on left side and click on New -> Class

sw9

10) In java class window provide Package name, Class name and click on Check-box “public static void main”.

sw10

11) Click on Finish will add the class in the project. Interface will look like this:

sw11

12) Under class you can start writing your script.

Here project is create and class have been added successfully. Now let’s install TestNG.

Install TestNG by downloading stand alone Jar file:

1) Go to the link and download TestNG jar fileClick Here

2) Extract TestNG file and remember the TestNG folder location saved in your system.

3) Right Click on project -> Build Path and click on Configure Build Path.

sw12

4) Click on Library tab and then click on Add External JARs…

sw13

5) Select testing-6.8.5.jar file and click on Open.

ecl2

6) Click OK. Once you click on OK, TestNG will be added to eclipse project.

7) Restart eclipse.

8) To verify testNG installation type @Test in the script.

ecl3

9) Once you type @Test you will see the error and on mouse over on it, you will get the options to correct it. This verifies that testNG have been installed successfully.

10) Click on Import ‘Test’(org.testng.annotations)

11) Once you click on Import ‘Test’(org.testng.annotations) option, TestNG will be imported to the project.

ecl4

12) To test the project in TestNG, right click on the project and select the Run as TestNG.

Directly install TestNG in eclipse without downloading Jar files:

1) Open eclipse and click on Help ->Install New Software.

2) Under work with type the URL – http://beust.com/eclipse

3) Press Enter button.

ecl5

4) Click in TestNG check-box and then click on Next button.

ecl6

ecl7

5) Again select TestNG option and click on Next.

ecl8

6) Accept the terms and conditions and click on Finish button.

ecl9

7) Once you click on Finish button, TestNG will get installed in Eclipse.

ecl10

It might could take little long time to install.

Similarly as above explained you can verify the installation and run your project in TestNG.

One Response to “Create a simple Java project and install TestNG in Eclipse.”

  1. Balakrishnan says:

    Doesnt work. The link http://beust.com/eclipse is broken or forbidden. Cannot install through eclipse or importing the jar file in the library also doesnt work. Hard luck!

Leave a Reply

Your email address will not be published. Required fields are marked *