TestNG - Suite Test

A test suite is a collection of test cases intended to test a behavior or a set of behaviors of software program. In TestNG, we cannot define a suite in testing source code, but it is represented by one XML file, as suite is the feature of execution. It also allows flexible configuration of the tests to be run. A suite can contain one or more tests and is defined by the <suite> tag.

<suite> is the root tag of your testng.xml. It describes a test suite, which in turn is made of several <test> sections.

The following table lists all the legal attributes that <suite> accepts.

Sr.No. Attribute & Description


The name of this suite. It is a mandatory attribute.



The level or verbosity for this run.



Whether TestNG should run different threads to run this suite.



The number of threads to use, if parallel mode is enabled (ignored other-wise).



The type of annotations you are using in your tests.



The default timeout that will be used on all the test methods found in this test.

In this chapter, we will show you an example having two test classes, Test1 & Test2, to run together using Test Suite.

Create a Class

Create a java class to be tested, say, MessageUtil.java in /work/testng/src.

* This class prints the given message on console.

public class MessageUtil {
   private String message;

   // Constructor
   // @param message to be printed
   public MessageUtil(String message) {
      this.message = message;

   // prints the message
   public String printMessage() {
      return message;

   // add "Hi!" to the message
   public String salutationMessage() {
      message = "Hi!" + message;
      return message;

Create Test Case Classes

Create a java class file named Test1.java in /work/testng/src.

import org.testng.Assert;
import org.testng.annotations.Test;

public class Test1 {
   String message = "Manisha";
   MessageUtil messageUtil = new MessageUtil(message);

   public void testPrintMessage() {
      System.out.println("Inside testPrintMessage()");
      Assert.assertEquals(message, messageUtil.printMessage());

Create a java class file named Test2.java in /work/testng/src .

import org.testng.Assert;
import org.testng.annotations.Test;

public class Test2 {
   String message = "Manisha";
   MessageUtil messageUtil = new MessageUtil(message);

   public void testSalutationMessage() {
      System.out.println("Inside testSalutationMessage()");
      message = "Hi!" + "Manisha";

Now, let's write the testng.xml in /work/testng/src , which would contain the <suite> tag as follows −

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

<suite name = "Suite1">

   <test name = "exampletest1">
         <class name = "Test1" />

   <test name = "exampletest2">
         <class name = "Test2" />


Suite1 includes exampletest1 and exampletest2.

Compile all java classes using javac.

/work/testng/src$ javac MessageUtil.java Test1.java Test2.java

Now, run the testng.xml, which will run the test case defined in the provided Test Case class.

/work/testng/src$ java org.testng.TestNG testng.xml

Verify the output.

  Inside testSalutationMessage()

  Total tests run: 2, Passes: 2, Failures: 0, Skips: 0

You can also check the test-output folder. Under the Suite1 folder, you can see two html files created, exampletest1.html and exampletest2.html, which would look as follows −

Suite Tests

Suite Tests
Kickstart Your Career

Get certified by completing the course

Get Started