TheDeveloperBlog.com

Home | Contact Us

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

TestNG @AfterMethod Annotation

TestNG @AfterMethod 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 @AfterMethod Annotation

The @AfterMethod annotation is specific to a class not to an XML file. The @AfterMethod annotated method will be invoked after the execution of each test method. Suppose there are four test methods means that @AfterMethod annotated method will be executed four times.

Let's understand the @AfterMethod annotation through an example.

Step 1: Open the Eclipse.

Step 2: We create a simple java project which contains the @AfterMethod annotated method.

After_Method.java

package com.TheDeveloperBlog;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
public class After_Method 
{
@AfterMethod
public void after_method()
{
System.out.println("This method will be invoked after the execution of each test method");
}
@Test
public void c_programmers()
{
System.out.println("I am a C programmer");
}
@Test
public void java_programmers()
{
System.out.println("I am a java programmer");
}
@Test
public void dotnet_developer()
{
System.out.println("I am a .Net Developer");
}
}

Step 3: Now, we create a testng.xml file to configure After_Method class.








 
 

Step 4: Run the testng.xml file. Right click on the testng.xml file and move the cursor down to Run As, and then click on the 1 TestNG Suite.

Output

TestNG @AfterMethod Annotation

Note: TestNG executes the test methods in alphabetical order.

In the above case, first c_programmers() method runs, then @AfterMethod annotated method is executed, thereafter dotnet_developer() method runs, then @AfterMethod annotated method is executed, and at the last java_programmers() method run, and then @AfterMethod annotated method will be executed.


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