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

1
7 comments
Avatar
Permanently deleted user

 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...

0

The second link answers your question

0
Avatar
Permanently deleted user

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 ?

0

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/

0
Avatar
Permanently deleted user

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

0
Avatar
Permanently deleted user

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"

0

Please sign in to leave a comment.