Adding Packages to testng.xml file, will explain you about creating and configuring TestNG test suite with packages which are developed/created in the java project. A Package may contain one or more classes in it. With this testng.xml configuration file we can include all the classes belongs to a particular package or its subpackages to the test suite.
Below are The Steps for Adding Packages to testng.xml file:
1.Create a java project with multiple packages and 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-packages.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="PackageTest"> <packages> <package name="com.test.firstpackage"/> <package name="com.test.secondpackage"/> <package name="com.test.thirdpackage"/> </packages> </test> <!-- Test --> </suite> <!-- Suite -- >
In the above code, packages will be reside in the “packages” tag and the each individual package will be in the “package” tag with “name” attribute.
4.Now execute the “testng-packages.xml” file from eclipse as TestNG suite.
Then you can see the following output.
This way we can configure the packages in the testng xml configuration file to execute the scripts as packages and can analyse the test results.