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.
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:
- Support for parameters.
- Supports dependent methods testing.
- Test configuration flexible.
- Supports powerful execution model.
- Embeds BeanShell for further flexibility.
- TestNG has a more elegant way of handling parameterized tests with the data-provider concept.
- For the same test class TestNG support for multiple instances.
- Extendibility of using different Tools and plug-ins like Eclipse, Maven, IDEA etc.
- Default JDK functions for runtime and logging (no dependencies).
- Supported different Annotations like @BeforeSuite, @AfterSuite, @BeforeClass, @AfterClass, @BeforeTest, @AfterTest, @BeforeGroups, @AfterGroups, @BeforeMethod, @AfterMethod, @DataProvider, @Factory, @Listeners, @Parameters, @Test.
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:
- In TestNG Annotations are easy to understand over JUnit.
- In TestNG there is no constraint like you have to declare @BeforeClass and @AfterClass, which is present in JUnit.
- 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.
- In TestNG enable you to grouping of test cases easily which is not possible in JUnit.
- TestNG supports following three 3 additional setUp/tearDown level:
@Before/AfterSuite, @Before/AfterTest and @Before/AfterGroup. - TestNG do not require extend any class.
- TestNG allows us to define the dependent test cases each test case is independent to other test case.
- 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.
- 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.
Happy Testing!!!
- Brief Introduction of TestNG – What is execution sequence of TestNG Annotations?
- Installation of TestNG in Eclipse – Selenium WebDriver Tutorial
- Selenium Training Series – Getting Started with Selenium IDE
- Why Selenium Server not required by Selenium WebDriver?
- How to Create Project in Eclipse IDE?
- Start Selenium WebDriver Test Script on your own – Selenium Tutorial
- Complete Guide on XPath in Selenium
- How To Access Links & Tables Using Selenium Webdriver?
- Selenium Tutorial: Introduction to Selenium Grid
- Selenium Core Extensions – Selenium Tutorial
5 thoughts on “Introduction of TestNG framework – Advantages of TestNG over Junit framework”
Hwow can we perform Parallel testing using J-unit
I want to do selenium online course. I am looking for fees and time periode but didn’t able to find it.
How to join class?
Very well explained… Thanks
Hi STC Team,Nice Tutorials.Thanks for sharing.One small request.Can you please publish the date, on top of the page,as to when this article was published.We can know how latest/updated the content is(since the content changes over time because of updates in the s.w).Thank You.
I have a query:
I want to know whether it is possible to know the test description in after class.
After every test completion, I want to update the result. How to get test result after test completion.