How to Run Testng from Command Line

How to run TestNG from command line

You need to have the testng.jar under classpath.

try C:\projectfred> java -cp "path-tojar/testng.jar:path_to_yourtest_classes" org.testng.TestNG testng.xml

Update:

Under linux I ran this command and it would be some thing similar on Windows either

test/bin# java -cp ".:../lib/*" org.testng.TestNG testng.xml

Directory structure:

/bin - All my test packages are under bin including testng.xml
/src - All source files are under src
/lib - All libraries required for the execution of tests are under this.

Once I compile all sources they go under bin directory. So, in the classpath I need to specify contents of bin directory and all the libraries like testng.xml, loggers etc over here. Also copy testng.xml to bin folder if you dont want to specify the full path where the testng.xml is available.

 /bin
-- testng.xml
-- testclasses
-- Properties files if any.
/lib
-- testng.jar
-- log4j.jar

Update:

Go to the folder MyProject and type run the java command like the way shown below:-

java -cp ".: C:\Program Files\jbdevstudio4\studio\plugins\*" org.testng.TestNG testng.xml

I believe the testng.xml file is under C:\Users\me\workspace\MyProject if not please give the full path for testng.xml file

Running TestNG via Command Line

Try:

java -cp ".;C:\Users\johndoe\Documents\My Docs\03_OE\Java\workspace\Maven\m2\repository\org\testng\testng\6.9.10\testng-6.9.10.jar;C:\Users\johndoe\Documents\My Docs\03_OE\Java\workspace\Maven\m2\repository\com\beust\jcommander\1.48\jcommander-1.48.jar;C:\Users\johndoe\Documents\My Docs\03_OE\Java\workspace\KeywordDrivenTool\JavaTestNBS\target\test-classes" org.testng.TestNG test.xml


Related Topics



Leave a reply



Submit