Eclipse JUnit 4 provides a NullPointerException

When I try to run the JUnit 4 test, I get a NullPointerException in Eclipse. JUnit3 is working.

I am trying to execute 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 am using OS X Snow Leopard with Java SDK 1.6.0_35 (from Apple). Both JDK and JUnit 4 are in my build path. Does the Java version have anything to do with the problem?

UPDATE:

OK, I'm an idiot without thinking about it. I installed Eclipse for C / C ++ developers, as I had to do something in C ++. But I also used the same instance for Android for Android with the Android SDK plugin, and I made some small Java applications. But I did not have Java development tools or Java EE developer tools. I installed them now and JUnit 4 is working now.

I think one of these tools is used for JUnit 4. Strange though JUnit 3 worked. In any case, it works now.

Thank you all for your support.

+4
source share
6 answers

OK, I'm an idiot without thinking about it. I installed Eclipse for C / C ++ developers, as I had to do something in C ++. But I also used the same instance for Android for Android with the Android SDK plugin, and I made some small Java applications. But I did not have Java development tools or Java EE developer tools. I installed them now and now JUnit 4 is working.

+10
source

I have the same problems, I am reinstalling ADT from version 22.3 to 23 because there is an update problem. The new version of ADT seems to exclude the Java Development Tool.

You can check "Help" β†’ "About" β†’ "Installation Details" for details.

So, I use the existing Juno update site in eclipse to install JDT (Juno - http://download.eclipse.org/releases/juno ), after that it works fine.

+1
source

Your org.junit.Test import causes a conflict with the class name. You might want to rename your class test, for example, ATest 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 (so as not to use the default package)

Source:

 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 sure it will also work on the lion.

0
source

There is a solution, yes. As described in UPDATE, the default is JUnit 4, which is not installed. After upgrading to JUnit 3, it works.

0
source

I had the same issue with the recently installed Eclipse Neon, and with ADT (Android, which includes Java and usually installs Junit).

I just installed JDT (Java Development Tools) and it works well after.

0
source

I had the same problem! Just reset the perspective (right click β†’ Reset) and it will work!

-1
source

Source: https://habr.com/ru/post/1440084/


All Articles