Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the responsive-lightbox domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the hueman domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114
Building a Test Suite in TestNG - Testingpool

Building a Test Suite in TestNG

In the previous post, we have learnt how to write a program in TestNG. In this post, we will see what is a TestSuite and its usage in TestNG.

What is a Test Suite?

In any project, you will have a bunch of test cases. In the previous post, we have seen how to execute a single program. What is , we need to execute the whole bunch of test cases altogether in TestNG. This will be possible by building a Test Suite in TestNG. Or in other words, you can say Test Suite is a XML file that includes the set of test cases which need to be executed.

TestNG provide a way to manage test execution. Those test cases may be dependent on each other or follow a certain execution order. You will create one testng.xml file to include all the test classes, packages, methods, parameters if required etc. (A pictorial presentation is given below having the attributes in Test Suite.)

TestSuite in TestNG


A basic structure of a testng.xml file:

This basic testng.xml given below contains the classes and its packages.

<suite name="Any user defined name" >
  <test name="Any user defined name">
    <classes>
      <class name="PackageName.ClassName"/>
       <class name="PackageName.ClassName"/>
    </classes>
  </test>
</suite>

Let’s understand step by step working of Test Suite:

Step#1 Right click on the project folder –> New –> File.

Create testng xml file

 

Step#2 A new window will open , give the name as testng.xml and click finish.

Save as testng xml

 

Step#3 It will create a new file where you can add classes that need to be executed. Suppose, we need to add the class as shown below in the figure.

Add class in testng suite

 

Step#4 Add the class into testng.xml (Test Suite).

<suite name="ExampleTestSuite" >
  <test name="Bank functionality">
    <classes>
      <class name="com.testsuite.example.Bank1"/>
    </classes>
  </test>
</suite>

step#5 To run the Test Suite , right click on testng.xml –> Run As –> TestNG Suite.

Run Test Suite in testNG

The class that is included in Test Suite.

public class Bank1 {

	@Test
	public void HDFCBank(){
		System.out.println("This is HDFC bank");
	}
}

 

Step#6 After running test suite, Test class will be executed and you will get the below output.

In console: 

TestNG output

Result of running Suite:

TestNG result

 


Building a Test Suite in TestNG including multiple classes:

Suppose, we have multiple Test classes. We can add those classes to the Test Suite as shown in the figure below.

Adding More classes in test suite

 

After running the whole suite , you will see the following output.

Test Suite output


 

Ask Question
Have any question or suggestion for us?Please feel free to post in Q&A Forum
Avatar photo

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...