Lets say there is a need to fully execute the entire group of test cases in TestNG, How cab we achieve this ?
- It will be possible by constructing a test suit in TestNG.
- Test suite is a testng.xml file that contains a set of test cases that need to be executed.
- To create and manage many test classes we need to create a testng.xml file.
- We configure the test run, set test definitions, include a test, method, class or package and set priority etc. in the testng.xml file.
Create TestNG XML File
- Right click on Project folder > Select TestNG > Convert to TestNG
- Click on next and then click on Finish button.
- It will add testng.xml file under your project folder.
Example testng.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="Demo1"/>
<class name="Demo2"/>
<class name="Demo3"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
testng.xml code Explanation:
- <suite>: suite tag defines the TestNG suite in testng.xml file. You can give any name to your suite using ‘name’ attribute.
- <test>: test tag defines the TestNG test in testng.xml file. You can give any name to your test using ‘name’ attribute.
- <classes>: classes tag defines multiple class in testng.xml file. We can multiple test class under classes tag.
- <class>: class tag defines the class name which you wants to consider in test execution in testng.xml file.
Execute a testng.xml file
- Right click on testng.xml –> Run As –> TestNG Suite.
- After running test suite, Test class will be executed and you will get the test-output folder contains testng report.