Running Tests with TestNG XML Suite

Running Tests with TestNG XML Suite

Running tests with a TestNG XML suite allows you to configure and control your test execution in a structured way. Here’s a step-by-step guide to help you run tests using a TestNG XML suite:


✅ 1. Create Your TestNG XML Suite File

This file typically has the .xml extension and describes the structure of your tests — such as which classes or methods to run.


Example: testng.xml

xml

Copy

Edit

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >

<suite name="MySuite" parallel="false">

  <test name="MyTest">

    <classes>

      <class name="com.example.tests.LoginTest"/>

      <class name="com.example.tests.HomePageTest"/>

    </classes>

  </test>

</suite>

✅ 2. Ensure Your Project Has TestNG Set Up

Make sure that:


TestNG is added to your project dependencies (via Maven, Gradle, or manually).


Your test classes/methods are annotated with @Test.


✅ 3. Run the TestNG XML Suite

There are multiple ways to run the suite:


πŸ”Ή Option 1: Using an IDE (e.g., IntelliJ or Eclipse)

Right-click the testng.xml file.


Click on Run 'testng.xml'.


πŸ”Ή Option 2: Using Command Line

If you are using the TestNG JAR directly:


bash

Copy

Edit

java -cp "path/to/testng.jar;path/to/your/classes" org.testng.TestNG testng.xml

πŸ”Ή Option 3: Using Maven

If you're using Maven with the maven-surefire-plugin, add this to your pom.xml:


xml

Copy

Edit

<build>

  <plugins>

    <plugin>

      <groupId>org.apache.maven.plugins</groupId>

      <artifactId>maven-surefire-plugin</artifactId>

      <version>3.1.2</version>

      <configuration>

        <suiteXmlFiles>

          <suiteXmlFile>testng.xml</suiteXmlFile>

        </suiteXmlFiles>

      </configuration>

    </plugin>

  </plugins>

</build>

Then run:


bash

Copy

Edit

mvn test

✅ 4. View the Test Results

TestNG generates reports in:


test-output/index.html


test-output/emailable-report.html


You can open them in a browser to review your results.

Learn Selenium JAVA Course in Hyderabad

Read More

Grouping Test Cases in TestNG

Introduction to TestNG Annotations

Visit Our IHUB Talent Training in Hyderabad

Get Directions

Comments

Popular posts from this blog

How to Install and Set Up Selenium in Python (Step-by-Step)

Feeling Stuck in Manual Testing? Here’s Why You Should Learn Automation Testing

A Beginner's Guide to ETL Testing: What You Need to Know