How To Create TestNG XML File And Execute TestNG.XML File
Create TestNG XML file:
In TestNG framework, we need to create Testng xml file to create and handle multiple test classes. We do configure our test run, set test dependency, include or exclude any test, method, class or package and set priority etc in the xml file.
Please be patient. The video will load in some time.
Steps to create TestNG XML file
Step 1: Create testng xml file
i. Right click on Project folder, go to New and select ‘File‘ as shown in below image.
ii. In New file wizard, add file name as ‘testng xml‘ as shown in below given image and click on Finish button.
iii. It will add testng xml file under your project folder.
Step 2 : Write xml code:
i. Now add below given code in your testng xml file.
<suite name="softwaretestingmaterial"> <test name="testngTest"> <classes> <class name="softwareTestingMaterial.STMTestNGClass" /> </classes> </test> </suite>
Note: You can choose any name for your Test Suite & Test Name as per your need.
ii. After giving appropriate names, now your testng xml file will looks like this:
The hierarchy in the testng xml file is very simple to understand.
Very first tag is the Suite tag<suite>, under that it is the Test tag<test> and then the Class tag<classes>. You can give any name to the suite and the test but you need to provide the correct name to the <classes> tag which is a combination of your Package name and Test Case name.
eg. Package Name is “softwareTestingMaterial”, Test Case Name is “STMTestNGClass”. So the Class Name should be softwareTestingMaterial.STMTestNGClass
Step 3 : Execute a testng xml
Now let’s run the xml. Run the test by right click on the testng xml file and select Run As > TestNG Suite.
Once the execution is done, you could view test result under the TestNg console.
You could find the complete TestNG tutorial here.
If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.