TestNG Annotations @AfterSuite (original) (raw)
Last Updated : 6 Aug, 2025
@AfterSuite is one of the TestNG Annotations. As the name defines, @AfterSuite is executed after the execution of all the test cases inside a TestNG Suite. This annotation allows developers to specify various actions to be taken after the execution of all the test cases inside a TestNG Suite.
Let’s understand the @AfterSuite annotation through an example.
**Step 1: In the Maven Project, create a TestNG Class that contains @AfterSuite.
**After_Suite.Java (@AfterSuite)
Java `
package com.geeksforgeeks.test;
import org.testng.annotations.AfterSuite; import org.testng.annotations.Test;
public class After_Suite {
@AfterSuite public void afterSuite() { System.out.println("TestNG runs the test cases in alphabetical order"); } @Test public void signup() { System.out.println("Test for signup"); } @Test public void login() { System.out.println("Test for login"); }
}
`
**Now, let’s explain what this code does:
**Package Declaration: After_Suite Class is on the com.geeksforgeeks.test package.
**Imports: After_Suite Class imports annotations and classes from the TestNG framework (org.testng.annotations.BeforeMethod and org.testng.annotations.Test).
**After_Suite Class: This is the main test class. It contains test methods and before class methods.
**afterSuite (@AfterSuite): This method is annotated with @AfterSuite, indicating that it should be executed after suite execution this suite contains many classes. It prints this ”TestNG runs the test cases in alphabetical order ” statement.
**Test Methods (@Test):
- Each test method is annotated with @Test, indicating that it is a test case.
- There are two test methods: signup() and login().
- Each test method prints its respective statement.
- After operating, the result is printed to the console.
**Step 2: Now, we create theAnnotationsTest.xml file to configure the After_Suite Class.
XML `
`
**Step 3: Run the AnnotationsTest.xml Right-click on theAnnotationsTest.xml file, move the cursor down to Run As and then click on the TestNG Suite.
.png)
Output of AfterSuite