TestNG Suite

Creating a TestNG Test Suite allows you to group and run multiple test classes, groups, or methods together using an XML configuration file. This is very useful for organizing your tests logically and controlling test execution.


What is a TestNG Test Suite?

Test Suite is defined in an XML file generally named as 'testng.xml'. It can:

  • Include multiple test classes

  • Run specific methods or groups

  • Control execution order

  • Pass parameters to tests


Below are the steps to create a TestNG Suite

Step 1: Create Your Test Classes


LoginTest.java

import org.testng.annotations.Test;

public class LoginTest {

    @Test
    public void loginWithValidUser() {
        System.out.println("✔ Login with valid user executed.");
    }

    @Test
    public void loginWithInvalidUser() {
        System.out.println("✔ Login with invalid user executed.");
    }
}



HomePageTest.java

import org.testng.annotations.Test;

public class HomePageTest {

    @Test
    public void checkTitle() {
        System.out.println("✔ Home page title check executed.");
    }

    @Test
    public void checkProfileButton() {
        System.out.println("✔ Profile button check executed.");
    }
}



Step 2: Create the testng.xml Test Suite File

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="MyTestSuite">

    <test name="Login Tests">
        <classes>
            <class name="LoginTest"/>
        </classes>
    </test>

    <test name="Home Page Tests">
        <classes>
            <class name="HomePageTest"/>
        </classes>
    </test>

</suite>


Save testng.xml file in the root of your project (or src/test/resources/ for Maven).

Step 3: Run the Test Suite

In Eclipse or IntelliJ:

  • Right-click on testng.xml

  • Select Run As > TestNG Suite

No comments:

Post a Comment