TestNG Intorduction

TestNG(Next Generation) is an open source testing framework written in Java and inspired from JUnit and NUnit, it is not only inherited existing functionality from Junit as well as introducing some new innovative functionality that make it powerful, easy to use, reliable, maintainable and testable codes.

.TestNG means Next Generation. TestNG is similar to JUnit but it is much more powerful than JUnit but still it’s inspired by JUnit. It is designed to be better than JUnit, especially when testing integrated classes. Pay special thanks to Cedric Beust who is the creator of TestNG.

TestNG eliminates most of the limitations of the older framework and gives the developer the ability to write more flexible and powerful tests with help of easy annotations, grouping, sequencing & parametrizing.

TestNG
Benefits of TestNG

  • HTML reports of Execution.
  • Logs
  • Support for parameters
  • Support for multi-threaded testing
  • Data Provider (Data driven Testing)
  • Supported by a variety of tools and plug-ins (Eclipse, Maven, etc…).
  • Listeners

 

 

Annotations

@Test

This annotation method will execute method as a test method or part of your test.

@BeforeMethod

This annotation method will execute before each test method.

@AfterMethod

The annotated method will be executed after each test method

@BeforeClass

This annotation method will execute before the first test method in the current class is invoked

@AfterClass

This annotation method will execute after all the test methods in the current class have been executed.

@BeforeTest

This annotation method will execute before any test method belonging to the classes inside the Test tag is executed

@AfterTest

This annotation method will execute after all the test methods belonging to the classes inside the Test tag have executed

@BeforeSuite

This annotation method will execute before all tests in this suite

@AfterSuite

This annotation method will execute after all tests in this suite

@DataProvider

This method is used in supplying data for a test method @BeforeGroups

@BeforeGroups

@BeforeGroups annotated method will run before the first test run of that specific group.

@AfterGroups

@AfterGroups annotated method will run after all test methods of that group completes its execution.

@Parameters

When you wants to pass parameters in your test methods, you need to use @Parameters annotation.

@Factory

When you wants to execute specific group of test cases with different values, you need to use @Factory annotation. An array of class objects is returned by @Factory annotated method and those TestNG will those objects as test classes.

@Listeners

@Listeners are used to with test class. It is helpful for logging purpose.

 

Leave a Reply

Your email address will not be published.