What is New in TestNG? and Difference Between TestNG and JUNIT? - TestingQ.com

-->Exclusive Portal for Testing Jobs

What is New in TestNG? and Difference Between TestNG and JUNIT?

TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use, such as:
  • Annotations. 
  • Flexible test configuration. 
  • Support for data-driven testing (with @DataProvider). 
  • Support for parameters. 
  • Allows distribution of tests on slave machines. 
  • Powerful execution model (no more TestSuite). 
  • Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc...). 
  • Dependent methods for application server testing.
If you want to learn TestNG you can download it and see its documentation at “http://testng.org/doc/index.html”.

TestNG is extensively used in Selenium automation and Code testing instead of Junit due to its advantages over it.

Using TestNG Selenium automation becomes simplified and also the Parallel execution using Selenium Grid becomes easy.
Advantages of TestNG over Junit:
  1. In Junit we have to declare @BeforeClass and @AfterClass which is a constraint whereas in TestNG there is no constraint like this.
  2. Additional Levels of setUp/tearDown level are available in TestNG like @Before/AfterSuite,@Before/AfterTest and @Before/AfterGroup
  3. No Need to extend any class in TestNG.
  4. There is no method name constraint in TestNG as in Junit. You can give any name to the test methods in TestNG
  5. In TestNG we can tell the test that one method is dependent on another method whereas in Junit this is not possible. In Junit each test is independent of another test.
  6. Grouping of testcases is available in TestNG whereas the same is not available in Junit.
  7. Execution can be done based on Groups. For ex. If you have defined many cases and segregated them by defining 2 groups as Sanity and Regression. Then if you only want to execute the “Sanity” cases then just tell TestNG to execute the “Sanity” and TestNG will automatically execute the cases belonging to the “Sanity” group.
  8. Also using TestNG your selenium testcase execution can be done in parallel.

To receive daily posted JOBS & Interview Questions
Just enter your email address below and click 'Submit'
Enter your email address:

Make sure to activate your subscription by clicking on the activation link sent to your email