Annotations are used to indicate the meaning of a note or a comment on a diagram to convey its meaning. They're also used by TestNG for the same reason. TestNG annotations are the lines of code that are written within your source test code logic to manage the flow of test execution. As a result, it's critical to annotate your processes in TestNG before running the tests. Because it won't know when to run a process that doesn't have an annotation, TestNG will ignore it.
Annotations in TestNG can be thought of as separate pieces of code that are inserted into a program's logic to handle the sequential execution of test methods. In other words, TestNG Annotations aid in determining the order in which tests should be run.
These annotations are derived from the Java language and are an important part of Selenium's Test Next Generation (TestNG) automation framework.
The symbol "@" appears at the start of a TestNG annotation, followed by the annotation name. You don't need anything to run TestNG annotations except the header file and the '@' symbol.
Different Kinds Of TestNG Annotations
There are ten different types of annotations in TestNG:
• @BeforeSuite - The @BeforeSuite function in TestNG runs ahead of all other test methods.
• @AfterSuite - The @AfterSuite function in TestNG runs after all other test methods have finished.
• @BeforeTest - In TestNG, the @BeforeTest function is called before all of the test methods in a folder are run.
• @AfterTest - The @AfterTest function in TestNG is called after all test methods in a folder have been run.
• @BeforeClass - Before the first method gathers the current class in TestNG, the @BeforeClass function is called.
• @AfterClass - In TestNG, when all of the current class's test methods have been completed, the @AfterClass method is invoked.
• @BeforeMethod - The @BeforeMethod method is called before each test method in TestNG.
• @AfterMethod - The @AfterMethod method in TestNG is called after each test method is run.
• @BeforeGroups - The @BeforeGroups function in TestNG executes before the test cases in that group. It is executed only once.
• @AfterGroups - TestNG's @AfterGroups function runs after all of the test cases in a given group have been run. It's just going to be used once.
The meanings for these TestNG annotations are self-explanatory. One of the most compelling reasons to use TestNG is that it is simple to understand.
Explore more on : TestNG Annotations-Benefits, Hierarchy
Get now : SDET Certification