Create a simple Java project and install TestNG in Eclipse.
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.
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.
3) Click OK button to continue.
4) Go to File -> New -> Project and click on Project.
5) Click on Java Project and then click on Next button.
6) Provide the project name and click on Next.
7) Finally click on Finish to add the project in Eclipse.
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
10) In java class window provide Package name, Class name and click on Check-box “public static void main”.
11) Click on Finish will add the class in the project. Interface will look like this:
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 file – Click 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.
4) Click on Library tab and then click on Add External JARs…
5) Select testing-6.8.5.jar file and click on Open.
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.
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.
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.
4) Click in TestNG check-box and then click on Next button.
5) Again select TestNG option and click on Next.
6) Accept the terms and conditions and click on Finish button.
7) Once you click on Finish button, TestNG will get installed in Eclipse.
It might could take little long time to install.
Similarly as above explained you can verify the installation and run your project in TestNG.