What is TestNG.xml ?

When you want to run the TestNG test, which you have created, there are two ways to do so.
If you want to run single test case, you can right click on the test, and Run it as TestNG Test. (form Eclipse).
But, if you want to run a set of test cases from various classes, then you need to specify them somewhere, because, you can’t click on each class and run it. Moreover, when running our test cases from the continuous integration tool ( like Jenkins), we need some configuration file which will tell us which test cases to run, if you need to pass some parameters at runtime, then to do that, like wise to achieve something more.
So, In TestNG, all these things are written in a xml file, called as TestNG.xml.
We can configure our test suite utilizing test methods, classes, packages, groups, and so on in single testng.xml file.
TestNG bolster parallel testing, Parameterization (Passing parameters values through XML 
configuration), Data Driven Testing(executing same test strategy numerous times utilizing diverse data) .
The testng.xml file allows lots of flexibility in selecting the test classes and test methods to be executed. You can exclude or include test methods or exclude and include groups.
You can specify the listener to be used by all test classes in the testng.xml file
How to create testing.xml file? 
Create testng suite file manually as below:
  1. Run once your project
  2. Refresh your project
  3. Now, “test-output” folder will get created under your project – unfold the folder
  4. Double click the ‘index.html’ file; it will get open in the Eclipse Browser window
  5. Click on the ‘.xml’ link given on the left panel
  6. The test suite XML will get opened on the right-side panel
  7. Take a copy of the XML content
  8. Right click your project >> New >> File
  9. Give name of your test suite file (with.xml extension e.g. testng.xml) and click finish
  10. Paste the content that you copied from the ‘index.html’ and amend your suite file as per your needs
Sample TestNG.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Aayush Corp Test suite">

<listeners>
<listener class-name="com.aayushCorp.utilities.ITestListenerClass" />
</listeners>

<test verbose="2" name="UserTests" >
<classes>
<class name="com.aayushCorp.appData.tests.UserTests"/>
</classes>
</test> <!-- Default test -->
</suite> <!-- Default suite -->
TestNG.xml is –
•          Controls test runs
•          Optional
•          File can have any name (.xml suffix advised
             TestNG creates “testng-failed.xml”, for easy re-run.
•          Root: <suite> (then <test>/<classes>/<method>)
•          Suite can also point to a list of additional xml suite files.
•          Some of the available specifications are described next.
Hope This helps !!!!
 

Leave Comment

Your email address will not be published. Required fields are marked *

Looking for learning Framework Development from Scratch? Lookout for Detailed Framework Development videos on YouTube here -

https://www.youtube.com/automationtalks

Get the Framework code at Github Repo: https://github.com/prakashnarkhede?tab=repositories