How to run TestNG test in cmd

Showing 1-2 of 2 messages
How to run TestNG test in cmd Grega G. 8/9/11 3:36 AM

I run my tests under Eclipse with TestNG. I have two files. First I
have .java class and the second file is testng.xml.

I run my test through the Eclipse where I run my .xml file. But now I
would like to do so that I could run my test in cmd.

Any suggestion how to do that??

Re: [testng-users] How to run TestNG test in cmd Krishnan Mahadevan 8/9/11 8:47 AM

My humble apologies for not responding to your personal note in time earlier (Was stuck with some other stuff and was also trying to figure out this myself)

Here's how you can do it:

Download the testng jar from :
Create a batch file which will have the following:

java -cp testng-6.1.1.jar;projects\MyProject\target\test-classes org.testng.TestNG projects\MyProject\src\test\resources\MyCustomSuite.xml

Explanation :
  • If you notice that I am specifying the class path as "-cp"
  • I have not specified any path for testng-6.1.1.jar, since it is available in my current directory.
  • I am appending the classpath (Note that I used ";" to append paths) with projects\MyProject\target\test-classes [This is where java should find my ClassA.class and ClassB.class files]
  • org.testng.TestNG is the main class from which execution of your suite should begin.
  • projects\MyProject\src\test\resources\MyCustomSuite.xml is the relative path of my suite.xml file from my current directory.
  • MyCustomSuite.xml looks like below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "">
<suite name="Suite" parallel="false">
    <parameter name="environment.toRun" value="QA" />
    <test name="Test1" preserve-order="true">
            <class name="testng.samples.ClassB">
                    <include name="iRunFirst"></include>
                    <include name="iRunSecond"></include>
            <class name="testng.samples.ClassA">
                    <include name="iRunFirst"></include>
                    <include name="iRunSecond"></include>

If you would like to have the capabilities of kicking off runs from outside eclipse, you should seriously consider build tools such as either Ant or Maven.
[ I have been using only Maven, which is why it took me sometime to figure out how to make use of just java and get the execution done from the command line. But it was a good learning :) ]

For using Ant to get your executions done, please read more at :

For using Maven to kick off your testng executions, please read more at :

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at