TestNG Test Suite (2024)
In this tutorial, we will understand TestNG Test Suite and how to create a multiple test suite and run it.
TestNG Tutorial :
Q: What is the TestNG test Suite?
Ans:
A test suite of software programs is a collection of test cases that are used to test a behavior or a set of behaviors. As suite is the feature of execution it is represented by an XML file and not defined in the testing source code in testNG.
The tests are run with a flexible configuration. A suite can consist of one or more tests. The suite is
interpreted as <suite>
. The foundation of testng.xml is <suite>
.
A test suite is described from it and many
<test>
sections are made from it.
Following are attributes with their descriptions that accept the<suite>
:
- Name: The compulsory attribute is the name of the suite.
- parallel: Parallel will help TestNG to decide whether it should run different threads to run this suite.
- Annotations: In your tests type of annotations is used.
- verbose: The level for the run.
- Thread count: The number of threads that are used. No need to count thread if Parallel mode is selected.
- Time count: The time used for completing all the test methods found in this test.
Let's two examples run together using the test suite.
The XML file will be created and it will be the main spot file where you configure your test run. Test dependency is set, exclude, or include any test, class, package, method, set priority, etc.
How TestNG XML is created?
Following are the steps to create a TestNG XML File for running the TestNG test suite:
- As given in the below image, Right-click on the Project folder->TestNG->Convert to TestNG.
- Provide the file name -> remove the thread count (we can edit as per our needs)->Click Finish.
- It will create
testng.xml
file, edit and make two tests as below:
This TestNG XML code is very easy to write and understand. As per above code have created multiple tests.<?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.techgeeknext.testcases.DatabaseTestCases"/> </classes> </test> <!-- Test --> <test name="Test2"> <classes> <class name="com.techgeeknext.testcases.LoginTestCases"/> </classes> </test> <!-- Test --> </suite> <!-- Suite -->
- Suite Name: Any suite name can be given and it will relate to the test suite name and it is
written as
<suite>
. - Test Name: Any test name can be given and will indicate test sets. It is written as
<test>
. - Classes Name: Any name cannot be given to the classes as it is the combination of package
and test case name. It is written as
<classes>
.
- Suite Name: Any suite name can be given and it will relate to the test suite name and it is
written as
- TestNG XML is created -> Run the TestNG suite.
- Right-click on the
testng.xml
file-> Run As-> TestNG Suite. - After running the TestNG Suite, below result is obtained as given below: