Before we look into TestNG Tutorial, we should know what is TestNG?
TestNG is an unit testing framework similar to Junit. TestNG is used by the developers for their development activities and perform Unit Testing before promoting the build from Development environment to QA environment.
It is highly recommended to go through Junit tutorial, before understanding TestNG.
Any action we perform on TestNG is based on Annotations. Annotations is an specialized method mapped to particular action. If we use any annotation then TestNG will perform that specified action.
Below are the list of Annotations of TestNG :
@BeforeSuite : BeforeSuite Annotated method will be used to run only once before all tests in the test suite have run.
@AfterSuite : AfterSuite Annotated method will be used to run only once after all the tests in the test suite have run.
@BeforeClass : BeforeClass Annotated method will be used to run only once before the first test method in the current class is run.
@AfterClass : AfterClass Annotated method will be used to run only once after all the test methods in the current class have run.
@BeforeTest : BeforeTest Annotated method will be used to run before any test method belonging to the classes inside the Tag is run.
@AfterTest : AfterTest Annotated method will be used to run after all the test methods belonging to the classes inside the tag have run.
@BeforeMethod : BeforeMethod Annotated method will be run before each test method.
@AfterMethod : AfterMethod Annotated method will be run after each test method.
@Test : Treats each @Test as individual test script.
The order of execution of TestNG Annotations are as below :