TestNG unit Testing Framework in Selenium
TestNG is a unit test framework designed for testing needs, TestNG is designed to cover all categories of tests: unit, functional, end-to-end, integration, etc.
It is inspired from JUnit and NUnit by adding new functionalities, which made TestNG more powerful than other unit test frameworks.
- Support for annotations
- Test that your code is multi-thread safe.
- Support for data-driven testing (with @DataProvider).
- Support for parameters.
- It is supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc...).
- Allows user to set execution priorities for the test methods
- Helps to generate reports
- To run test cases in the order which we provide
- To create Dependent Test cases
- JUnit still requires the before/after class methods to be static, which limits what you can do prior to the running of tests; TestNG never has this issue.
- TestNG @Configuration methods can all take an optional argument to their annotated methods in the form of an ITestResult, XmlTest, Method, or ITestContext. This allows you to pass things around that JUnit wouldn't provide you. JUnit only does this in listeners, and it is limited in use.
- TestNG comes with some pre-made report generation classes that you can copy and edit and make into your own beautiful test output with very little effort. Just copy the report class into your project and add a listener to run it. Also, ReportNG is available.
- TestNG has a handful of nice listeners that you can hook onto so you can do additional AOP style magic at certain phases during testing.
- Some units of code can only be tested in a multiple-JVM scenario. For example, testing the opening of a connection (TCP socket or HTTP connection) and the integrity of the information retrieved from it is not possible (or very hard) to test with only one JVM, which is the only option that exists with JUnit.
- JUnit was designed to have all tests run within a single process within a single class. It is also designed with the constraint that all tests are atomic and independent of any other code outside the test being run and that the lifecycle for these tests are independent for each test. This is all great for low-level testing units of code, but not for client/server scenario tests.
There are advantages that make TestNG superior to JUnit. Some of them are
- Advance and easy annotations
- Execution patterns can be set
- Concurrent execution of test scripts
- Test case dependencies can be set
- Parallel Execution
Follow the below steps to install TestNG to java project in eclipse.
1. Open Eclipse IDE, then goto help
2. Select install new software
3. Click on Add
4.Specify the name as TestNG
5.Specify the Location as https://brust.com/eclipse
6. Click “Ok᾿
7.Select TestNG checkbox
9. Accept license
10. Click OK on the warning message
11. Click Yes Which will re-start the Eclipse IDE,
Try..Catch..Finally in Selenium and Java