TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

TestNG @AfterTest Annotation

TestNG @AfterTest Annotation with Testng Tutorial, Introduction, Testng Installation, Features of Testng, Suite Test, Testng Exception Test, Group Test, Plug with Ant, Plug with Eclipse, etc.

<< Back to TESTNG

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

package com.TheDeveloperBlog;

import org.testng.annotations.Test;

public class Fixed_deposit 
{
 @Test
	public void fixed_deposit()
 {
	 System.out.println("Fixed Deposit");
 }
@Test
 public void roi()
 {
	 System.out.println("Rate of Interest");
 }
}

Recurring_Deposit.java

package com.TheDeveloperBlog;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
public class Recurring_deposit 
{
@Test 
public void recurring_deposit()
  {
	  System.out.println("Recurring Deposit");
  }
@AfterTest
public void after_test()
{
	System.out.println("After test execution..");}}

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

package com.TheDeveloperBlog;
mport org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
public class Recurring_deposit 
{
	
@AfterTest
public void after_test()
{
	System.out.println("After test execution..");
}
@Test 
public void recurring_deposit()
  {
	  System.out.println("Recurring Deposit");
  }
}

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




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf