TheDeveloperBlog.com

Home | Contact Us

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

TestNG @AfterClass Annotations

TestNG @AfterClass Annotations 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 @AfterClass Annotation

@AfterClass: The @AfterClass annotated method will be executed after all the test methods of a current class have been invoked.

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

Step 1: Open the Eclipse.

Step 2: We create a simple java project.

Class1.java

package com.TheDeveloperBlog;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;

public class Class1 
{
 @AfterClass
 public void after_class()
 {
	 System.out.println("The above are the programming languages");
 }
 @Test
 public void testcase1()
 {
	 System.out.println("C");
 }
 @Test
 public void testcase2()
 {
	 System.out.println("C++");
 }
 @Test
 public void testcase3()
 {
	 System.out.println("Java");
 }

}

Class2.java

package com.TheDeveloperBlog;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
public class Class2 
{
 @AfterClass
 public void after_class()
 {
	 System.out.println("The above are the automation testing tools");
 }
 @Test
 public void testcase1()
 {
	 System.out.println("Selenium");
 }
 @Test
 public void testcase2()
 {
	 System.out.println("Rational Functional Tester");
 }
 @Test
 public void testcase3()
 {
	 System.out.println("Cucumber");
 }
 @Test
 public void testcase4()
 {
	 System.out.println("eggPlant");
 }
}

We define @AfterClass annotated method in the above classes. We define after_class() method in Class1 which runs after all the test methods of Class1 have been executed, and we also define @BeforeClass annotated method, i.e, after_class() in Class2 as well which runs after all the test methods of Class2 have been executed.

Step 3: Now, we create testng.xml file to configure the above two classes.









 
 

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

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