Software Testing Class

Introduction of TestNG framework – Advantages of TestNG over Junit framework

In Selenium WebDriver training tutorial we have seen how to run Selenium scripts using JUnit framework. Until now we have execute selenium tests but we have not generated reports in JUnit. In this Selenium training article series we are introducing powerful new testing framework called TestNG. The TestNG framework means Next Generation testing framework, so we are seeing what all next generation features available in TestNG, also I will talk about advantages of TestNG over Junit. I will be discussing about different ways of using TestNG features in my coming articles.

I do not say that don’t use JUnit, but you should really consider using TestNG for your next project. Apparently TestNG is more complete and clean than JUnit.

 

What is TestNG?

TestNG is testing framework inspired from most popular JUnit framework used for the Java programming language. The TestNG framework is introduced to overcome the limitations of JUnit framework. Most of the automation users are using this framework because of its advantages & more supported features. Until we have executed selenium test script but not even generated test reports. So using this TestNG framework we will learn how to generate test reports.

TestNG Framework

 

Features of TestNG Framework:

TestNG supports many powerful features & it is easy to use. Let’s see what all new features are supported in new testing framework:

TestNG supports annotations which are very helpful to guide test case executions. Similarly in JUnit, the TestNG annotations are always preceded by the ‘@’ symbol. It permit you do parallel execution of test cases & we can also skip the test cases effortlessly while executing test cases.

TestNG is specially designed to cover all types testing categories like Unit, Functional testing, Integration testing, End-to-end etc. Using TestNG framework allows us to generate test reports in both HTML and XML formats. Using ANT with TestNG, we can generate primitive Testng reports as well.

 

Advantages of TestNG over Junit:

  1. In TestNG Annotations are easy to understand over JUnit.
  2. In TestNG there is no constraint like you have to declare @BeforeClass and @AfterClass, which is present in JUnit.
  3. As method name constraint is present in JUnit, such method name constraint is not present in TestNG and you can specify any test method names.
  4. In TestNG enable you to grouping of test cases easily which is not possible in JUnit.
  5. TestNG supports following three 3 additional setUp/tearDown level:
    @Before/AfterSuite, @Before/AfterTest and @Before/AfterGroup.
  6. TestNG do not require extend any class.
  7. TestNG allows us to define the dependent test cases each test case is independent to other test case.
  8. 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.
  9. Parallel execution of Selenium test cases is possible in TestNG.

 

Conclusion:
If you enjoy reading this article please make sure to share it with your friends. Please leave your questions/tips/suggestions in the comment section below and I’ll try to answer as many as I can.

In Next article, we will see “Steps to install TestNG in Eclipse”.
You can also Subscribe by E-mail and get All New articles delivered directly to your Inbox.

 

Enter your email address:

Check email in your inbox for confirmation to get latest updates Software Testing for free.

 

Happy Testing!!!

Exit mobile version