Javatpoint Logo
Javatpoint Logo

TestNG @AfterTest annotation

@AfterTest: The test method under the @AfterTest annotated method is executed after the execution of all the test methods of the available classes which are kept inside the tag in the testng.xml file in the suite.

Let's understand through an example.

First case: When @AfterTest annotated method exists at the end.

Step 1: Open the Eclipse.

Step 2: We create two java projects. Suppose we create a project of Deposits which contains two modules Fixed Deposits and Recurring Deposits.

Fixed_Deposit.java

Recurring_Deposit.java

In the above case, we use @AfterTest annotation in Recurring_Deposit, which means that the test annotated method, i.e., after_test() will be executed only when all the test methods of Recurring_Deposit class are executed.

testng.xml

Output

TestNG @AfterTest annotation

Second case: When @AfterTest annotated method exists in the beginning of a class file.

Recurring_deposit.java

In the above code, we place the @AfterTest annotated method in the beginning.

Output

TestNG @AfterTest annotation

We got the same output as in the first case, so we conclude that @AfterTest annotated method can be placed anywhere in the class file. The @AfterTest annotated method run after the execution of all the test methods present in the classes which are kept inside the folder. In the above case, @AfterTest annotated method is available in the Recurring_deposit class, so TestNG will look at the testng.xml file and determine which test folder is containing the Recurring_deposit class. In this case, Recurring_deposit class is defined inside the Recurring Deposit folder, so all the classes available in the Recurring Deposit folder are completed first and then @AfterTest annotated method is executed.

Note: Once the execution is completed, there is a requirement to remove the cookies, delete the process or close the connection, so @AfterTest annotated method is used for this purpose.


Next TopicTestNG Annotations




Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA