TestNG Annotations and their Execution Sequence

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
 Below are the different annotations used in TestNG

@BeforeSuite: The annotated method will be run only once before all tests in this suite have run.

@AfterSuite: The annotated method will be run only once after all tests in this suite have run.

@BeforeTest: The annotated method will be run before any test method belonging to the classes inside the <test> tag is run.

@AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the <test> tag have run.

@BeforeClass: The annotated method will be run only once before the first test method in the current class is invoked.

@AfterClass: The annotated method will be run only once after all the test methods in the current class have run.

@BeforeMethod: The annotated method will be run before each test method.

@AfterMethod: The annotated method will be run after 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:
TestNG Annotations
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.
Please refer below youtube video to get more details on TestNG Annotations using program:



No comments:

Post a Comment