Create TestNG.xml File:
- There is a need to fully execute the entire group of test cases in TestNG.
- This 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: Go through ==>> Create / Execute TestNG Script
1) Right click on Project folder, go to New and select File.
2) In New file wizard, add file name = “testng.xml” and click on Finish button.
3) It will add testng.xml file under your project folder.
Example TestNG.xml file for Single Class:
1 2 3 4 5 6 7 8 9 10 11 12 13 | <suite name="Suite One" > <test name="Test One" > <classes> <class name="package_Name.Class_Name" /> </classes> </test> </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.
Example TestNG.xml file for Multiple Class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <suite name="Suite One" > <test name="Test One" > <classes> <class name="package_Name.Class_Name1" /> <class name="package_Name.Class_Name2" /> <class name="package_Name.Class_Name3" /> <class name="package_Name.Class_Name4" /> </classes> </test> </suite> |
Execute a testng.xml file to create 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 below output.
How To Create TestNG XML File And Execute TestNG.XML File and How to Create TestNG Test Suite to run test in a Group