Last Updated on April 24, 2020 by Scientech Easy
What is TestNG?
TestNG, where NG stands for “Next Generation” is the next step towards writing test cases. It is an open-source automation testing framework based on JUnit (in Java) and NUnit (in C#).
It can be integrated with Selenium or any other automation tool to provide multiple features like assertions, reporting, parallel test execution, etc.
TestNG was developed by Cedric Beust to overcome the deficiency in JUnit by introducing some more functionalities and features. It mainly uses Java annotations to configure and write test methods.
Therefore, TestNG has gained a lot of popularity in a very short time which is widely used nowadays as an automation testing framework with Selenium WebDriver. It can be used for unit, integration, functional and end-to-end testing.
Why do we use TestNG Framework with Selenium?
There is the following purpose of using TestNG in selenium. They are as follows:
1. Selenium WebDriver does not generate test reports but by integrating TestNG with Selenium WebDriver, you can easily generate test reports or test results in a proper readable format to know about how many test cases are passed, failed, and skipped.
2. You can execute selective test cases. For example, suppose, you have 25 test cases and you want to execute only 5 test cases, so you can easily execute 5 test cases using TestNG framework.
3. Using TestNG, we can also execute failed test cases separately. For example, suppose, you have 5 test cases and out five test cases, the first three test cases are successfully executed but the fourth test case is failed due to some error.
You can run the fourth test case using testng-failed.xml file option provided by TestNG in the output folder. You will have to run this XML file to execute the only failed test case.
4. We can easily integrate TestNG framework with tools like Maven, Jenkins, etc.
5. Verification can be achieved with the help of only TestNG.
6. We can organize test cases easily in a proper way.
Features of TestNG Framework
Now that you are familiarized a little with TestNG, So let’s move forward and see more about the features provided by TestNG. The most important features of TestNG are as follows.
1. Object-oriented: TestNG is written in Java so it uses more object-oriented and Java features.
Using priority, we can execute test methods in TestNG in a different order. We can also set priority whether the dependent test method has to be executed or not in case the earlier test method fails.
6. Parameterization of test methods: This feature allows users to pass the parameter values directly through XML file to the test methods used in tests.
8. Multi-threaded execution: This feature is mainly used to execute test cases in a multi-threaded environment. Using this feature, we can execute multiple test cases in parallel to reduce the execution time.
9. Test report: TestNG internally generates an XML and HTML test report in a readable format by default for its test execution. Generation of test report includes a number of test cases run, passed, failed, and skipped. You can also add custom reports if required.
10. Main method: There is no need for the static main method in the TestNG. The method need not be static.
We will discuss these features in more detail in the further tutorial.
Advantage of TestNG over JUnit
1. TestNG generates HTML test reports in a readable format.
2. Test method can be grouped and prioritized more easily which is not possible in JUnit.
How to Download & Install TestNG Framework?
There are the following ways to download, install, and run TestNG. They are as follows.
Step by step guide to Install TestNG plugin in Eclipse
Before going to install TestNG plugin into eclipse, please make sure that you have Eclipse installed in your system. You can get the latest version of Eclipse.
Let’s start the installation process of TestNG in Eclipse.
Step 1: a. Open your Eclipse application and click to help option on the menu bar.
b. Choose the option “Eclipse Market place…”.
Step 2: In Eclipse Marketplace dialog box, type TestNG in the search box as shown in the below screenshot and click the search button or press enter key.
Step 3: Now click on the install button.
Step 4: A new window will be open for feature selection but you do not have to change anything, Just click on the confirm button.
Step 5: Click on “I accept the terms of the license agreement” and then click Finish.
Step 6: If you get a Security Warning dialog box, just click OK.
Now, wait for the installation to finish.
Step 7: After installation, Eclipse will prompt you for a restart, just click Yes.
Step 8: After the restart, you can verify that TestNG has been indeed successfully installed or not. For this, click Window option in Eclipse > Preferences and see if TestNG is included on the Preferences list.
That’s end TestNG Installation.
There is another way to install the TestNG into Eclipse. Just follows all the below steps.
1. Open your Eclipse application.
2. Go to Help and click on “Install New Software”.
3. Click on add button. You will get a text dialog box.
4. Enter “TestNG site” into the Name box and enter the URL http://beust.com/eclipse into the Location box. Once done, click on OK button.
5. On clicking OK, TestNG update site will get connected to Eclipse. A software window will be opened to download TestNG plugin under the TestNG site.
6. Select TestNG and click on the Next button.
7. The eclipse will calculate the software requirement to download TestNG and will display installation details screen. Click on Next on the details screen.
8. Accept the license agreement and click on finish. The download and installation of the TestNG plugin into Eclipse will start.
9. In case you get any warning window then click on the OK button.
10. Once the installation is complete, Eclipse will prompt you to restart it. Click on Yes option on the window prompt.
11. After the restart, verify that TestNG plugin has been indeed successfully installed or not. For this, click Window option in Eclipse > Preferences and see if TestNG is included on the Preferences list.
That’s end TestNG Installation.
Hope that this tutorial has covered almost all the important points related to features of TestNG framework. I hope that you will have successfully downloaded and installed TestNG plugin in your Eclipse and enjoyed this tutorial.
Thanks for reading!!!