How To Use Annotations in TestNG
Posted By : Manish Kumar | 23-Apr-2018
A considerable lot of us get confused about the pattern of running test methods while creating a test script, it's the most important to run test cases in correct order, and for that either we need to create them in one by one order in a series or make them in different classes and call them one by one which is again a different problem.
@AfterSuite: Method with such annotation will be executed after all the test cases in the suite are executed.
@BeforeTest: This annotation makes the method to run before any test method that is declared in the test run
@AfterTest: The annotated method will run after all the test cases in the test are executed.
@BeforeGroups: The annotated method will run just before any of the method which is defined in the group.
@BeforeClass: This annotation is used to run a method before any method of the class is executed
@AfterClass: This annotation is used when a method is needed to run after all the methods in the class.
@BeforeMethod: The method with this annotation will run before each test method that is queued in the execution
@AfterMethod: The method with this annotation will run after each test method that is queued in the execution
- It gives a liberty of grouping and prioritizing the test cases without any alteration in our code.
- We simply need to write our business logic and insert TestNG annotations as per our requirement of execution.
- And rest all will be tackled by the TestNG.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Manish Kumar
Manish is Adaptive and passionate to learn new technical skills, have knowledge of testing and love to play badminton in free time