tags:

views:

261

answers:

3

Ok, I am like other and new to jUnit and having a difficult time trying to get it working. I have searched the forum but the answers provided; I am just not getting. If anyone out there could lend me a hand I would greatly appreciate it.

Let me provide the basics: OS: mac OS X.6

export JUNIT_HOME="/Developer/junit/junit4.8.1"
export CVSROOT="/opt/cvsroot"
export PATH="/usr/local/bin:/usr/local/sbin:/usr/localmysql/bin:/opt/PalmSDK/Current/bin/:/usr/local/mysql/bin:$PATH:$JUNIT_HOME:$CVSROOT"
export CLASSPATH="$CLASSPATH:$JUNIT_HOME/junit-4.8.1.jar:$JUNIT_HOME"

I can compile a test class from a java file, however when I try to then run the test java org.junit.runner.JUnitCore MyTest.class I get the following:

JUnit version 4.8.1
Could not find class: MyTest.class

Time: 0.001

OK (0 tests)

Now I have been in the directory with the MyTest.class which is just somewhere in my file system, I tried moving the source folder to the "junit" folder and the "junit/junit4.8.1" folder and the same result. I cannot even run the tests that came with junit.

Thanks patrick

A: 

It is not having problems finding JUnit -- it is finding that okay. It can't find MyClass, so the directory of that class (given that it is packageless) needs to be in the classpath.

Kathy Van Stone
That is was I was thinking but turns out it was my mistake. Thanks for the advice.
Patrick
A: 

Remove .class from MyTest.class i.e. java org.junit.runner.JUnitCore MyTest

ezmia
I honestly feel a little silly, looks like my problem was forgetting that the java command is case sensitive. Once I typed it out with the right case then it worked just fine. Thank you to everyone that got back to me so promptly! I appreciate all of your help and will most certainly refer back to this thread when I try testing a more complex project.Thanks againPatrick
Patrick
A: 

Is MyTest really in the default package? If not, then you need to give the entire package-qualified name. In other words, if MyClass has a statement

package com.myself;

and lives in

/myproject/src/com/myself/MyClass.java

and you compiled into

/myproject/classes

then /myproject/classes must be on your CLASSPATH and you must

java org.junit.runner.JUnitCore com.myself.MyTest

Come to think of it, I see now that you're appending .class to the class name, so even if it's in the default package, you should just say

java org.junit.runner.JUnitCore MyTest
Jonathan Feinberg
Yeah, including the ".class" was part of my problem as was not using the right case. Once I fixed that I was ok. I didn't need to worry about the classpath since it is just in the default package.
Patrick