Recent Posts

Saturday, 9 December 2017

TestNG Annotations


     Here is the list of all TestNG annotations.
1. @Test
     Attaches a class or a method to become the part of the test.

2. @BeforeTest
     Instructs the method to run before any test method related to the classes which are inside the <test> tag as per the <testng.xml> file.

3. @AfterTest
     Halts a method from execution till all the test methods finish their execution. These methods belong to the classes defined in the <test> tag of <testng.xml> file.

4. @BeforeMethod
     Allows a method to run before executing any of the @test annotated methods.

5. @AfterMethod
     Allows a method to take off after all of the @test annotated methods finish their execution.

6. @Parameters
     You can use this annotation for passing the parameters to the test methods.

7. @DataProvider
     It marks a method as a data source for the test. Every @DataProvider annotated method must always return the value as <Object[ ][ ]>. You can use it in any of the @Test annotated methods.

8. @BeforeClass
     The method annotated with @BeforeClass gets executed once before the first test method of the current class.

9. @AfterClass
     The method annotated with @AfterClass gets run once after finishing all the test methods in the current class.

10. @BeforeGroups
     It sets up the method to run before the first test method belonging to any of the groups involved in the execution.

11. @AfterGroups
     It sets up the method to run after the execution of all the test methods belonging to any of the groups participating in the test.

12. @BeforeSuite
     Any such method will get called before any of the suites runs from the test.

13. @AfterSuite
     Any such method will stay its execution until all other methods in the current test suite get executed.

14. @Factory
     You use it to execute any specific group of test cases with varied values. It returns an array of test class objects as the <Object[ ]>.

15. @Listeners
     You can use them with the test classes for the logging function.

Advantages of using TestNG annotations.
     There are many benefits of using the TestNG annotations in the project.
  • They are easier to understand.
  • You can group the test cases using the appropriate annotation.
  • You can do parallel testing.
  • You can pass extra parameters to annotations.
  • They are strongly typed, so the compiler will catch any error outright.

No comments:

Post a Comment