Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

Why do we use TestNG rather than JUnit and NUnit?

Open 2 Answers 60 Views
0 2

I just wanted to know How TestNG is different from JUnit and NUnit. Why do we use TestNG rather than JUnit and NUnit?​

2 Answers


TestNG is a next generation testing framework of JUnit and NUnit which have enhanced functionalities for making it more useful:

1. It has Flexible test configuration.

2. It has support for data-driven testing

3. It has support for parameters.

4. It allows distribution of tests on slave machines.

5. Powerful execution model (no more TestSuite).

6. It is Supported by a variety of tools and plug-ins

7. Dependent methods for application server testing.

Due to its advantages, the automation testing company extensively uses TestNG for Selenium automation and code testing instead of JUnit. For automation testing company , TestNG Selenium automation becomes simplified and the parallel execution using Selenium Grid becomes easy. Also, TestNG have a lot of features in it.

Advantages of TestNG over Junit:
1. In TestNG there is no constraint like you have to declare @BeforeClass and @AfterClass, which is present in JUnit.

2. Additional Levels of setUp/tearDown level are available in TestNG like @Before/AfterSuite,@Before/AfterTest and @Before/AfterGroup

3. TestNG provides different type of Annotations which are easy to understand over JUnit.

4. TestNG allows you grouping of test cases easily which is not possible in JUnit.

5. In TestNg you can give any name to the test methods.

6. TestNG allows us to define the dependent test cases each test case is independent to other test case.

7. TestNG allows us to execute of test cases based on group. Let’s take a scenario where we have created two set of groups “Regression” & “Sanity”. If we want to execute the test cases under Sanity group then it is possible in TestNG framework.

8. Parallel execution of Selenium test cases is possible in TestNG.

answered by (570 points)
edited by

TestNG was initially developed by individual developer,Cédric Beust (cedric at, who wanted to overcome limitations JUnit has.

JUnit had limitations like it did not have parallel execution, parameterized execution and you do not have option to choose tests you want to execute through an xml file.


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.
  • Run your tests in arbitrarily big thread pools with various policies available (all methods in their own thread, one thread per test class, etc...).
  • Test that your code is multithread safe.
  • Flexible test configuration.
  • Support for data-driven testing (with @DataProvider).
  • Support for parameters.
  • Powerful execution model (no more TestSuite).
  • Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc...).
  • Embeds BeanShell for further flexibility.
  • Default JDK functions for runtime and logging (no dependencies).
  • Dependent methods for application server testing

That is the reason TestNG is more preferred. 

answered by

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.