- An annotation is a tag or metadata that provides additional information about class, interface, or method in TestNG.
- TestNG are the lines of annotation code that are put into the program / business logic, to control how to run the methods given below.
- TestNG also has the facility to pass parameters with annotation.
Advantages Of TestNG Annotations in Selenium:
- They are easy to understand.
- You can group test cases using appropriate annotations.
- You can do parallel test.
- You can pass extra parameters for annotation.
- They are strongly typed, so the compiler will completely catch any errors.
Execution Sequence of TestNG Annotations

Basic Annotations:
Annotations that are used most often on a daily basis in TestNG.
@Test, @BeforeClass, @AfterClass, @BeforeMethod, @AfterMethod.
Advanced Annotations:
Annotations used on special Situation / setup / configuration
Group Annotations : @BeforeGroups, @AfterGroups
Suite related Annotations : @BeforeSuite, @AfterSuite, @BeforeTest, @AfterTest
Annotation with Description:
@BeforeSuite:
All tests of this suit will be annotated only once before running.
@AfterSuite:
After running all the tests of this suit, the only way to annotated will be run only once.
@BeforeClass:
The first test method in the current class will be annotated only once before applying.
@AfterClass:
The annotated method will be run only once after all the testing methods of the existing class are run.
@BeforeTest:
The annotated method will be run before any test method related to the classes to be played.
@AfterTest:
Annotated methods will be run after all test methods that are going to be inside the class in the <Test> tag.
@BeforeGroups:
List of groups that will run before this configuration method. This method is guaranteed to be run shortly before the first test method under any of these groups.
@AfterGroups:
List of groups, which will run after this configuration method. This method is guaranteed immediately after using the final examination method under any of these systems.
@BeforeMethod:
The method annotated before each test method will be run.
@AfterMethod:
After each test method the annotated method will be run.