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.
This annotation method will execute method as a test method or part of your test.
This annotation method will execute before each test method.
The annotated method will be executed after each test method
This annotation method will execute before the first test method in the current class is invoked
This annotation method will execute after all the test methods in the current class have been executed.
This annotation method will execute before any test method belonging to the classes inside the Test tag is executed
This annotation method will execute after all the test methods belonging to the classes inside the Test tag have executed
This annotation method will execute before all tests in this suite
This annotation method will execute after all tests in this suite
This method is used in supplying data for a test method @BeforeGroups
@BeforeGroups annotated method will run before the first test run of that specific group.
@AfterGroups annotated method will run after all test methods of that group completes its execution.
When you wants to pass parameters in your test methods, you need to use @Parameters annotation.
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 are used to with test class. It is helpful for logging purpose.