Adding Classes to testng.xml file
Adding Classes to testng.xml file, will explain you about creating and configuring TestNG test suite with classes which are developed/created in the java project. A Class may contain one or more methods in it. With this testng.xml configuration file we can include all the methods belongs to a particular class to the test suite.
Below are The Steps for Adding Classes to testng.xml file:
1.Create a java project with multiple classes in each package.
2.In the above project; created 3 packages called (com.test.firstpackage, com.test.secondpackage and com.test.thirdpackage) and each package had 2 classes.
3.Now create a testng.xml file (here the xml file name is “testng-classes.xml”)
with below code/configuration content.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Suite"> <test name="ClassTest"> <classes> <class name="com.test.firstpackage.FirstClassInFirstPackage"/> <class name="com.test.firstpackage.SecondClassInFirstPackage"/> <class name="com.test.secondpackage.FirstClassInSecondPackage"/> <class name="com.test.secondpackage.SecondClassInSecondPackage"/> <class name="com.test.thirdpackage.FirstClassInThirdPackage"/> <class name="com.test.thirdpackage.SecondClassInThirdPackage"/> </classes> </test> <!-- Test --> </suite> <!-- Suite →
In the above code, Classes will be reside in the “classes” tag and the each individual class will be in the “class” tag with “name” attribute.
4.Now execute the “testng-classes.xml” file from eclipse as TestNG suite. Then you can see the following output.
This way we can configure the classes in the testng xml configuration file to execute the scripts as classes and can analyse the test results.