How to run tests from the command line ? (IntelliJ Idea + Java +TestNG)
Answered
Hi, I'm kind of new to Java and IntelliJ Environments
I managed to create TestNG tests inside IntelliJ and run them.
What are the ordered steps that I need to do in order to be able to run from the command line
I tried different approaches and nothing worked so far
Thanks
Please sign in to leave a comment.
Hello,
Take a look at these articles for some tips: http://testng.org/doc/documentation-main.html#running-testng, https://stackoverflow.com/questions/11896791/how-to-run-testng-from-command-line
On the first link it says
Assuming that you have TestNG in your class path
How can I know if TestNG is in my class path ?
Also I don't see any bin folder on my out folder of IntelliJ...
The second link answers your question
I tried to work according to that link but I didn't succeed.
I don't understand how can I compile TestNG...
Also I don't have properties file or bin folder.
Maybe you can give me a series of steps to follow ?
Do you mean "how to compile test classes"? You could use javac from command line: http://www.sergiy.ca/how-to-compile-and-launch-java-code-from-command-line/
I did according to the link and I get
Error: Could not find or load main class org.testng.TestNG
Caused by: java.lang.ClassNotFoundException: org.testng.TestNG
I'm running like this
java -cp "C:\Temp\JavaProjectOfTests\out\production\JavaProjectOfTests\Tests;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.2.6\plugins\testng\lib" org.testng.TestNG C:\Temp\JavaProjectOfTests\out\production\JavaProjectOfTests\testng.xml
Hi,
Finally I managed to run tests from the command line, still I'm not sure if is the right way.
What I did at the end is
1) Create a new folder and put there the JAR of my test project and also the JARs of TestNG (I take them from C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.2.6\plugins\testng)
2) Run like this
java -cp "PathToFolderCreatedOnStep1" org.testng.TestNG "PathToXMLFile"