简体   繁体   中英

Could not find class: org.junit.tests.AllTests - UBUNTU/LINUX

I'm trying to install apache-ant to my Ubuntu 11.10 and I'm stuck trying to setup JUnit.

The official-page steps to set it up are:

  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

The second step I change it as bash suggested to

export CLASSPATH=/my/home/directory/JUnit/junit4.10/junit-4.10.jar

When I ask echo $CLASSPATH the answer is: /my/home/directory/JUnit/junit4.10/junit-4.10.jar

which looks like to be a correct answer. But whe I try the third step I get this:

JUnit version 4.10
Could not find class: org.junit.tests.AllTests

Time: 0,001

OK (0 tests)

I double checked the old posts of the same problem for MAC and Windows but nothing seems to fit me. Any suggestion?

Thanks in advance.

I ran into the same problem on my debian machine. The junit docs are misleading. And sourceforge led me to the wrong download package. This is how I got it working:

First make sure you download the zip file here:

http://sourceforge.net/projects/junit/files/junit/4.10/

Then unzip. I unzipped to ~/java . So my installation directory was ~/java/junit4.10 .

Next you need to add 2 paths to your CLASSPATH : the jar file and the installation directory. This is mentioned in the junit docs , but it's easy to gloss over.

So just to be explicit:

  1. Download zip file here
  2. Unzip to your Junit Home (in my case, ~/java )
  3. export CLASSPATH=$CLASSPATH:~/java/junit4.10/junit-4.10.jar
  4. export CLASSPATH=$CLASSPATH:~/java/junit4.10/

Then try:

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

And you should see something like:

JUnit version 4.10
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
............................................................
..........................................................
Time: 12.21

OK (535 tests)

Your instructions mention JUnit 4.6, but you seem to be using JUnit 4.10. Maybe things changed between the versions?

Looking at the API documentation , I see that the class AllTests is in the package org.junit.runners , not org.junit.tests as you are using. Try running it with:

java org.junit.runner.JUnitCore org.junit.runners.AllTests

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM