Annotations in TestNG

In this blogpost, we will focus on understanding the various annotations supported in TestNG.

TestNG annotation is a piece of code that is inserted in the program to control how the methods below are to be run.

The important annotation of TestNG are depicted in the below table.

Annotation Syntax Description
@BeforeSuite public void The method will be run only once, before all the tests in the suite are executed.
@BeforeGroups public void The method will be run once, before all the configured group tests are executed.
@BeforeClass public void The method will be run only once before the first test method in the class in called.
@BeforeTest public void The method will be run before any test method belonging to the classes inside the tag is run.
@BeforeMethod public void The method will be run before each test method (@Test).
Annotation Syntax Description
@AfterSuite public void The method will be run only once, after all the tests in the suite are executed.
@AfterGroups public void The method will be run once, after all the configured group tests are executed.
@AfterClass public void The method will be run only once after the first test method in the class in called.
@AfterTest public void The method will be run after any test method belonging to the classes inside the tag is run.
@AfterMethod public void The method will be run after each test method (@Test).
@Test public void Used with class or method, used to annotate test class or method

Visit Execution order of TestNG Annotations, to learn more about execution order of the above mentioned annotations, and a working example of annotations.

That is all from this blogpost, hope it helps you!

Cheers 🙂

Advertisements

#testng-annotations