TestNG unit Testing Framework in Selenium Webdriver
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.
- 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 a 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 testing low level units of code, but not for client/server scenario tests.
There are advantages which 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 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 http://brust.com/eclipse
7.Select TestNG check box
10.Click OK on warning message
11.Click Yes Which will re-start the eclipse IDE,
Try..Catch..Finally in Selenium and Java
|Join My Facebook Group|
Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.