Skip to content
Advertisement

How to run TestNG from command line

How exactly do I run a .java TestNG project from a command line?

I have read through the TestNG documentation, and tried the following to no avail:

JavaScript

… with the following testng.xml file in my project:

JavaScript

The error I get is this:

JavaScript

Obviously, I am not referencing TestNG correctly in my command line. Does anyone know how to get this working?

Advertisement

Answer

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

JavaScript

Directory structure:

JavaScript

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.

JavaScript

Update:

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

JavaScript

I believe the testng.xml file is under C:UsersmeworkspaceMyProject if not please give the full path for testng.xml file

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement