Selenium Lesson 20 – Introduction to TestNG

TestNG is a testing framework developed in the lines of JUnit and NUnit. It is mainly use to execute the Unit test cases and now a days automated test cases. It has more advance features than Junit and NUnit.

TestNG provides lot of annotations to simple use and more flexibility in test execution.

 

Now a days TestNG become most popular test execution framework in test automation. most used annotation are below.

 

AnnotationDescription
@BeforeSuiteThe annotated method will be run only once before all tests in this suite have run.
@AfterSuiteThe annotated method will be run only once after all tests in this suite have run.
@BeforeClassThe annotated method will be run only once before the first test method in the current class is invoked.
@AfterClassThe annotated method will be run only once after all the test methods in the current class have run.
@BeforeTestThe annotated method will be run before any test method belonging to the classes inside the <test> tag is run.
@AfterTestThe annotated method will be run after all the test methods belonging to the classes inside the <test> tag have run.
@BeforeGroupsThe list of groups that this configuration method will run before. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked.
@AfterGroupsThe list of groups that this configuration method will run after. This method is guaranteed to run shortly after the last test method that belongs to any of these groups is invoked.
@BeforeMethodThe annotated method will be run before each test method.
@AfterMethodThe annotated method will be run after each test method.
@DataProviderMarks a method as supplying data for a test method. The annotated method must return an Object[ ][ ], where each Object[ ] can be assigned the parameter list of the test method. The @Test method that wants to receive data from this DataProvider needs to use a dataProvider name equals to the name of this annotation.
@FactoryMarks a method as a factory that returns objects that will be used by TestNG as Test classes. The method must return Object[ ].
@ListenersDefines listeners on a test class.
@ParametersDescribes how to pass parameters to a @Test method.
@TestMarks a class or a method as a part of the test.

 

most popular annotations are

  1. @Test
  2. @Dataprovider
  3. @BeforeTest
  4. @AfterTest
  5. @Parameters

 

in next post we will learn how to use these annotation and execute the test case using TestNG.

You might also like More from author