How to run TestNG xml suites from the command prompt

132 views
Skip to first unread message

MCD dotCom

unread,
Feb 3, 2022, 10:07:45 PM2/3/22
to testng-users
Hello,

I have a testng xml file (testng1.xml)   at the root directory. In command prompt, I typed the following:

cd to project directory
org.testng.TestNG testng1.xml
Error: Could not find or load main class org.testng.TestNG
Caused by: java.lang.ClassNotFoundException: org.testng.TestNG


How can I run the TestNG xml file from the command prompt?project1.pngproject2.png

Krishnan Mahadevan

unread,
Feb 3, 2022, 10:18:44 PM2/3/22
to testng...@googlegroups.com
From the screenshot it looks like you are already on a maven project. 

So why not just use “mvn test” to run your tests ?

Maven surefire plugin can be configured for more specifics ( even if your pom does not refer to it explicitly its there by default from the parent super pom file )


Thanks & Regards
Krishnan Mahadevan

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

From: testng...@googlegroups.com <testng...@googlegroups.com> on behalf of MCD dotCom <mycheap...@gmail.com>
Sent: Thursday, February 3, 2022 10:12:20 PM
To: testng-users <testng...@googlegroups.com>
Subject: [testng-users] How to run TestNG xml suites from the command prompt
 
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/1b30b6a5-f5c2-48c1-8cfb-80427da5f4adn%40googlegroups.com.

MCD dotCom

unread,
Feb 4, 2022, 3:38:46 PM2/4/22
to testng-users
Thank you! I have already used maven commands and it worked. I am also interested to learn to run testNG tests from the command prompt without using maven commands. I will have a requirement soon where I am not use maven. 

⇜Krishnan Mahadevan⇝

unread,
Feb 6, 2022, 11:20:00 PM2/6/22
to testng-users
You would need to manage your classpath by setting it up via Java args and point it to the directory wherein TestNG jars are existing. There's nothing much beyond that to be very honest.

On the contrary, build tools such as Maven/Gradle exist so that you and me don't have to manage our classpaths (which can get pretty long, when you have a lot of jars to refer to, not to forget the fact that you would need to download them and put them up in a lib folder, and then you may perhaps stand to get exposed to the same fully qualified class existing in multiple jars.. its a nightmare !)


Thanks & Regards
Krishnan Mahadevan

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

Reply all
Reply to author
Forward
0 new messages