Open In App

TestNG Annotations – @AfterSuite

The Concept Annotations is introduced in Java 1.5. The Popular Annotation in Java is @override. We use the same annotation concept in TestNG.

In TestNG, there are 10 Annotations

  1. @BeforeSuite
  2. @AfterSuite
  3. @BeforeTest
  4. @AfterTest
  5. @BeforeClass
  6. @AfterClass
  7. @BeforeMethod
  8. @AfterMethod
  9. @BeforeGroups
  10. @AfterGroups

In this article, we will learn about @AfterSuite.

What is @AfterSuite?

@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.

Example of @AfterSuite

Let’s understand the @AfterSuite annotation through an example.

Step 1: Open the Eclipse IDE.

Step 2: Create a Maven Project.

Step 3: After Creating the Maven Project, the project exploration will look like the below image.

Package Explorer Image

Package Explorer Image

Step 4: Create a TestNG Class that contains @AfterSuite.

After_Suite.Java (@AfterSuite)

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:

Step 5: Now, we create the AnnotationsTest.xml file to configure the After_Suite Class.

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="suite">
    <test name="test1">
        <classes>
               <class name="com.geeksforgeeks.test.After_Suite" /> 
        </classes>
    </test>
</suite>

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

Output

Output of AfterSuite

Output of AfterSuite

Article Tags :