What is pom xml and testng xml

Say suppose we have a scenario where we need to execute only a set of TestNG.xml files from the wide range of available xml suite files. It is like we want to run only the specific tests that are in testng.xml files and some times we may again need to kick off other testng.xml files. But for sure we don't want to execute all the suites and wait for them to complete the execution.

One way that we can actually do this by specifying the required testng.xml files in suiteXmlFiles using maven surefire plugin like below. But here when ever you want to execute set of testng.xml files, you have to keep changing them based on your needs. In the previous article we have seen an example to Execute testng.xml using Maven surefire plug-in

And the same can be used to run TestNG xml file from you command line, by using the following command:

Note that by default, maven surefire plugin will be looking xml files which are located at the root folder of project.

Now let us try to execute multiple testng suite files: -

We can do this in the same way which we have done in the above, but here we will pass multiple testng.xml files as below :-

To execute multiple xml files from command line, we can define a variable in suite file configuration and parametrize them from command line like below:

And below is the command to kick off a specified set of suite files by using , which lets us to specify "List of .

Below is the command to execute only single testng.xml file: -

Below is command to parametrize multiple testng.xml files using Maven :-

Example Maven project to parametrize and choose which TestNG xml suites to run from command line.

If you want to execute something like below, first try to create a simple maven project and add packages like below or as you like and execute.

Below image shows the maven project structure with multiple test packages like Patients, Appointments, Visits etc.

Below Image shows the tests to be verified for Patients related tests. And the same are added to testNG.xml named as 'patienttests.xml'.

Below image shows the maven command to execute 'patienttests.xml' and 'admintests.xml' tests

Below image shows the resulted output after execute above test suites

We can pass single testng.xml file or multiple testng.xml file using the same command. This will be very helpfull when you want to execute tests frequently on your machine or to validate results by only executing certain test suites.

Hope this helps you. Please feel free to comment if you have any issues / suggestions on the above article.