• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running JUnit test suite from command line

 
ParagM Pmahajan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34860
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show the command you are using that gives that error?
 
ParagM Pmahajan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34860
369
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne .
The problem was in my classpath.
After I corrected it , it is working fine now .
Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic