Reputation: 6526
When I try to run a JUnit 4 test i get a NullPointerException in Eclipse. JUnit3 though works.
I'm trying the following test class:
import static org.junit.Assert.fail;
import org.junit.Test;
public class Test {
@Test
public void test() {
fail("Not yet implemented");
}
}
Here is the Exception Stack Trace:
java.lang.NullPointerException
at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate$ClasspathLocalizer.localURL(JUnitLaunchConfigurationDelegate.java:420)
at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate$ClasspathLocalizer.entryString(JUnitLaunchConfigurationDelegate.java:409)
at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate$ClasspathLocalizer.addEntry(JUnitLaunchConfigurationDelegate.java:396)
at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate$ClasspathLocalizer.localizeClasspath(JUnitLaunchConfigurationDelegate.java:387)
at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate.getClasspath(JUnitLaunchConfigurationDelegate.java:364)
at org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate.launch(JUnitLaunchConfigurationDelegate.java:147)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:855)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:704)
at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1047)
at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1251)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
I'm using OS X Snow Leopard with Java SDK 1.6.0_35 (from Apple). Both JDK and JUnit 4 are in my build path. Has the Java Version something to do with the problem ?
UPDATE:
Ok I'm an idiot not thinking of this. I installed Eclipse for C/C++ Developers as I had to do something in C++. But I also used the same instance to develop for Android with the Android SDK plugin and I did some small Java Applications. But I didn't have the Java Development Tools or the Java EE Developer Tools installed. I installed them now and JUnit 4 works now.
I guess one of this Tools is used for JUnit 4. Strange though that JUnit 3 worked. Anyway it works now.
Thank you all for your support though.
Upvotes: 4
Views: 8974
Reputation: 3079
I had the same problem with Eclipse Neon newly installed, and with ADT (Android, which includes Java, and normally installs Junit).
I just installed JDT (Java Development Tools), and it works well after.
Upvotes: 0
Reputation: 132
I had the same issue! Just reset the perspective (Right click->Reset) and it will work!
Upvotes: -2
Reputation: 838
I have the same problems, I reinstall the ADT from version to 22.3 to 23 because the upgrade issue. It seems that the new version ADT excludes the 'Java Development Tool'.
You can check the 'Help'->'About'->'Installatoin Details' for details.
So I use the existed Juno upgrade site in eclipse to install the JDT (Juno - http://download.eclipse.org/releases/juno), after that, it works fine.
Upvotes: 1
Reputation: 1781
The solution is, yes, As your UPDATE describes, the default is JUnit 4, which haven't installed. Once changing to JUnit 3, it works.
Upvotes: 0
Reputation: 6526
Ok I'm an idiot not thinking of this. I installed Eclipse for C/C++ Developers as I had to do something in C++. But I also used the same instance to develop for Android with the Android SDK plugin and I did some small Java Applications. But I didn't have the Java Development Tools or the Java EE Developer Tools installed. I installed them now and JUnit 4 works now.
Upvotes: 10
Reputation: 15769
Your import org.junit.Test conflicts with the class name. You might want to rename your class Test to e.g. ATest to get:
java.lang.AssertionError: Not yet implemented
at org.junit.Assert.fail(Assert.java:91)
at ATest.test(ATest.java:8)
Another option might be to put Test in a package (as not to use the default package)
Source code:
import static org.junit.Assert.fail;
import org.junit.Test;
public class ATest {
@Test
public void test() {
fail("Not yet implemented");
}
}
Tested with Eclipse Juno on Max OS 10.8.0
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-10M3811)
Java HotSpot(TM) Client VM (build 20.10-b01-428, mixed mode)
I am pretty sure this would also work on lion.
Upvotes: 0