It's not a secret anymore!*
The moose likes Testing and the fly likes Running JUnit test suite from command line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Running JUnit test suite from command line" Watch "Running JUnit test suite from command line" New topic
Author

Running JUnit test suite from command line

ParagM Pmahajan
Greenhorn

Joined: Nov 16, 2011
Posts: 10
Hi ,
I have created a test suite of JUnit test cases and I can successfully run this suite from Eclipse.
I want to now run this suite from the command line.

This suite consists of 2 tests: Searchvm19 and createItem2vm.
I have successfully compiled both these classes but when I try to compile the suite, I get a "cannot find symbol" error for these classes.
The classes are present in the same directory and I have included them in the classpath when I try to compile the suite.

Code:



Error:

TestSuite1.java:14: error: cannot find symbol
ts1.addTestSuite(Searchvm19.class);
^
symbol: class Searchvm19
location: class TestSuite1

TestSuite1.java:15: error: cannot find symbol
ts1.addTestSuite(createItem2vm.class);
^
symbol: class createItem2vm
location: class TestSuite1
2 errors

What am I doing wrong ?

Thanks in advance .
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30938
    
158

Can you show the command you are using that gives that error?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
ParagM Pmahajan
Greenhorn

Joined: Nov 16, 2011
Posts: 10
Hi Jeanne ,

The command is :

javac -classpath junit.jar;selenium-java-client-driver.jar;Searchvm19.class;createItem2vm.class C:\eclipse\eclipse-java-helios-SR1-win32\eclipse\JunitWS\SeleniumTraining\src\com\org\tests\TestSuite1.java

I also tried running a single JUnit test from the command line but ended up with a similar problem.
I could compile the JUnit test successfully and the class file gets created in the correct location.
But when I try to run it using:

C:\Program Files\Java\jdk1.7.0_01\bin>java org.junit.runner.JUnitCore C:\eclipse\eclipse-java-helios-SR1-win32\eclipse\JunitWS\SeleniumTraining\src\com\org\tests\Nav.class

I get an error:

JUnit version 4.8.1
Could not find class: C:\eclipse\eclipse-java-helios-SR1-win32\eclipse\JunitWS\SeleniumTraining\src\com\org\tests\Nav.class
Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribbing

I don't know why it is not able to find the class even though it exists in the said location.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30938
    
158

You might try:
javac -classpath "junit.jar;selenium-java-client-driver.jar;." C:\eclipse\eclipse-java-helios-SR1-win32\eclipse\JunitWS\SeleniumTraining\src\com\org\tests\TestSuite1.java

This uses the working directory rather than listing out individual class files. (Also, not sure if having your code in the default package is causing problems."

For the second command, you didn't specify a classpath at all. This means Java doesn't know where to find junit, hamcrest, etc.
java org.junit.runner.JUnitCore C:\eclipse\eclipse-java-helios-SR1-win32\eclipse\JunitWS\SeleniumTraining\src\com\org\tests\Nav.class
ParagM Pmahajan
Greenhorn

Joined: Nov 16, 2011
Posts: 10
Thanks Jeanne .
The problem was in my classpath.
After I corrected it , it is working fine now .
Thanks again.
 
Consider Paul's rocket mass heater.
 
subject: Running JUnit test suite from command line