Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
660 views
by Contributing Tester (74 points)

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

1 like 0 dislike
by Expert (570 points)
edited by

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

Annotations:
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.

0 like 0 dislike
by

TestNG was initially developed by individual developer,Cédric Beust (cedric at beust.com), 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.

From TestNG.org

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. 


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...