tags:

views:

1500

answers:

5

I just installed JUnit but I can't get it to work:

C:\tools\junit4.6>java org.junit.runner.JUnitCore org.junit.tests.AllTests.
JUnit version 4.6
Could not find class: org.junit.tests.AllTests.

Time: 0

OK (0 tests)

This are my environment variables:

CLASSPATH=.;C:\Program Files\Java\jre1.5.0_11\lib\ext\QTJava.zip;c:\tools\junit4
.6\junit-4.6.jar;c:\tools\junit4.6\
JAVA_HOME=c:\Program Files\Java\jdk1.6.0_07

I just followed these steps:

Below are the installation steps for installing JUnit:

  1. unzip the junit4.6.zip file
  2. add junit-4.6.jar to the CLASSPATH. For example: set classpath=%classpath%;INSTALL_DIR\junit-4.6.jar;INSTALL_DIR
  3. test the installation by running java org.junit.runner.JUnitCore org.junit.tests.AllTests.

What could be wrong?

+2  A: 

Could not find class: org.junit.tests.AllTests.

If it is not a typo try removing the dot from the end of the classname?

Mark
A: 

If you observe you are giving the Path under the classpath.remove it and try. And go the jar file directory and unjar the jar file and see org.junit.tests.AllTests exists or not.

Giridhar
A: 

I was having an error just like this (but by classpath was correct), so I copied the test case directory from the ZIP from org/junit/ to junit.

Then use:

java org.junit.runner.JUnitCore org.junit.tests.AllTests junit.tests.AllTests

and everything ran fine.

Walter
A: 

I am on OS X.

I had the same problem.

The solution was to re-check my $CLASSPATH.

In .profile in my home directory I had:

$ANT_HOME="ant/ant.jar"

I changed it to:

$ANT_HOME="ant"

and changed the PATH and CLASSPATH entries by adding /ant.jar to the {$ANT_HOME} entries.

Here is what my classpath and path look like in my .profile with Ant, JUnit, and Cobertura installed and working:

export JUNIT_HOME="junit" export ANT_HOME="ant" export COBERTURA_HOME="cobertura/cobertura-1.9.3" export PATH="/usr/local/bin:/usr/local/sbin:$PATH:{$JUNIT_HOME}/junit-4.7.jar:$JUNIT_HOME:$COBERTURA_HOME:{$ANT_HOME}/bin" export CLASSPATH="$CLASSPATH:$ANT_HOME:$JUNIT_HOME/junit-4.7.jar:$JUNIT_HOME:$COBERTURA_HOME"

Hopefully this helps someone else. This was really painful the first time. I'm still working on getting Cobertura to work in Eclipse and Netbeans.. .sigh..

A: 

C:\Documents and Settings\xxx>set CLASSPATH=%CLASSPATH%;C:\JUnit\junit 4.8.1\junit-4.8.1.jar;C:\JUnit\junit4.8.1

Note the directory structure marked in bold

C:\JUnit\junit4.8.1 is the JUNIT_HOME

abhishek