TestNG uses annotations to help developers to write the tests. The following is a table containing information about all the annotations provided by TestNG and a brief description of them. I will cover them in detail in separate tutorials specific to their usages.
TestNG Test Configuration Annotations
|@BeforeSuite||The annotated method will be executed before any tests declared inside a TestNG suite.|
|@AfterSuite||The annotated method will be executed after any tests declared inside a TestNG suite.|
|@BeforeTest||The annotated methods will be executed before each test section declared inside a TestNG suite.|
|@AfterTest||The annotated methods will be executed after each test section declared inside a TestNG suite.|
|@BeforeGroups||BeforeGroups annotated method will run before any of the test method of the specified group is executed.|
|@AfterGroups||AfterGroups annotated method will run after any of the test method of the specified group gets executed.|
|@BeforeClass||BeforeClass annotated method is executed before any of the test method of a test class.|
|@AfterClass||AfterClass annotated method is executed after the execution of every test methods of a test class are executed.|
|@BeforeMethod||These annotated methods are executed before the execution of each test method.|
|@AfterMethod||These annotated methods are executed after the execution of each test method.|
|@DataProvider||Marks a method as a data providing method for a test method. The said method has to return an Object double array (Object[ ][ ]) as data.|
|@Factory||Marks a annotated method as a factory that returns an array of class objects (Object[ ]). These class objects will then be used as test classes by TestNG. This is used to run a set of test cases with different values.|
|@Listeners||Applied on a test class. Defines an array of test listeners classes extending org.testng.ITestNGListener. Helps in tracking the execution status and logging purpose.|
|@Parameters||This annotation is used to pass parameters to a test method. These parameter values are provided using the testng.xml configuration file at runtime.|
|@Test||Marks a class or a method as a test method. If used at class level, all the public methods of a class will be considered as a test method.|
Refer this table of TestNG Annotations whenever you are in confusion.
Happy Learning !!