views:

626

answers:

3
+1  Q: 

JUnit4 in Eclipse

I'm trying to run some JUnit test units in eclipse 3.5, but with no luck at all.

JUnit3 works fine.

When I create the JUnit4 Test unit, eclipse offers to add the JUnit library to the class-path. I accept, but when i check to see if it was added in the project's properties panel, I can see JUnit4 was added, but no JARS where included.
If I choose edit, the combo says "JUnit 4", and just below "Current location: Not Found".

When I launch a JUnit4 test, I get an error saying and internal error occurred, NullPointerException.

I've read for about two days now, and all references say eclipse INCLUDES JUnit4, but somehow, there seems to be something i'm missing.

I've tried re-creating my projects, and creating test in brand new ones with no luck.

package test;

import static org.junit.Assert.*;

import org.junit.Test;

public class AuthServiceTest {

    @Test
    public final void testValidateCredentials() {
        fail("Not yet implemented"); // TODO
    }

}

[Edit] I've added junit-4.8.1.jar to the project's classpath, and eclipe's classpath, but still the same problem. [Edit2] I also added junit-dep-4.8.1.jar, since i'm not sure if these dependencies are necessary, but no change.

A: 

Download junit4.jar and put it on your classpath.

Open your run configurations, go to classpath, and see if referenced libraries is present under user entries.

In case that doesn't work, get a fresh installation of eclipse.

Bozho
I've already tried adding junit-4.8.1.jar to my classpath, but still the same problem.
Hugo
Did you also modify the classpath in the launch?
djna
I have now, same error.
Hugo
get a fresh installation of eclipse. there is something wrong with yours.
Bozho
+1  A: 

In my Eclipse installation JUnit 4 is provided, it's in plugins\org.junit4_4.3.1\junit.jar

If you can't find it, then I guess that you may need to download it.

You can associate your JUnit with the Eclipse JUnit settings in

Windows->Preferences->Java->Build Path->User Libraries

Select JUnit there, and you can add and edit JARs.

djna
A: 

It appears that the Eclipse 3.5 from Fedora's repository doesn't include JUnit, and installing the appropriate package didn't include it either.
Another Debian PC presented the same issue. A clean download from eclipse.org solved the problem.

I will report this bug at some point :)

Hugo