2

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.

Solarin
  • 31
  • 2
  • 5

2 Answers2

5

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)
klenwell
  • 6,978
  • 4
  • 45
  • 84
  • Been struggling with this for some time now. Thanks for the list of things to do! I'm still failing one of the tests, but I'm not running the ubuntu build on ubuntu, so... https://bugs.launchpad.net/ubuntu/+source/junit4/+bug/1001351 – Sakamoto Kazuma Feb 01 '13 at 18:36
0

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
Jesper
  • 202,709
  • 46
  • 318
  • 350
  • Hi Jesper! Yes you are right, I'm trying to install 4.10 but the procedure specifies 4.6, sorry for that. But unfortunately I tried you suggestion and what I get is: – Solarin Mar 17 '12 at 17:47
  • Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/runner/JUnitCore Caused by: java.lang.ClassNotFoundException: org.junit.runner.JUnitCore at java.net.URLClassLoader$1.run(URLClassLoader.java:217) – Solarin Mar 17 '12 at 17:52
  • at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) – Solarin Mar 17 '12 at 17:52
  • Could not find the main class: org.junit.runner.JUnitCore. Program will exit. – Solarin Mar 17 '12 at 17:53
  • That sounds like the classpath is not set correctly. Try with the `-cp` option: `java -cp junit-4.10.jar org.junit.runner.JUnitCore org junit.runners.AllTests` (if `junit-4.10.jar` is in the current directory). – Jesper Mar 18 '12 at 07:34
  • Hi Jesper, no luck. I've got the same error... thanks anyway. – Solarin Mar 18 '12 at 17:46