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!!!