125
What is TestNG Annotation?
TestNG Annotation is a piece of code which is inserted inside a program or business logic used to control the flow of execution of test methods.
List of TestNG Annotations
TestNG Annotation | Description |
---|---|
@BeforeSuite | The @BeforeSuite annotated method will run before the execution of all the test methods in the suite. |
@AfterSuite | The @AfterSuite annotated method will run after the execution of all the test methods in the suite. |
@BeforeTest | The @BeforeTest annotated method will be executed before the execution of all the test methods of available classes belonging to that folder. |
@AfterTest | The @AfterTest annotated method will be executed after the execution of all the test methods of available classes belonging to that folder. |
@BeforeClass | The @BeforeClass annotated method will be executed before the first method of the current class is invoked. |
@AfterClass | The @AfterClass annotated method will be invoked after the execution of all the test methods of the current class. |
@BeforeMethod | The @BeforeMethod annotated method will be executed before each test method will run. |
@AfterMethod | The @AfterMethod annotated method will run after the execution of each test method. |
@BeforeGroups | The @BeforeGroups annotated method run only once for a group before the execution of all test cases belonging to that group. |
@AfterGroups | The @AfterGroups annotated method run only once for a group after the execution of all test cases belonging to that group. |
Hierarchy of the TestNG Annotations:
- @BeforeSuite
- @BeforeTest
- @BeforeClass
- @BeforeMethod
- @Test
- @AfterMethod
- @AfterClass
- @AfterTest
- @AfterSuite
Benefits of using TestNG Annotations:
- TestNG Annotations made the life of testers very easy. Based on your requirements, you can access the test methods, i.e., it has no predefined pattern or format.
- You can pass the additional parameters to TestNG annotations.
- In the case of TestNG annotations, you do not need to extend any test classes.
- TestNG Annotations are strongly typed, i.e., errors are detected at the compile time.
Next TopicTestNG Annotation Attributes