Eclipse JUnit 4 给出 NullPointerException

2024-01-02

当我尝试运行 JUnit 4 测试时,我在 Eclipse 中收到 NullPointerException。 JUnit3 虽然可以工作。

我正在尝试以下测试类:

import static org.junit.Assert.fail;
import org.junit.Test;

public class Test {

    @Test
    public void test() {
        fail("Not yet implemented");
    }

}

这是异常堆栈跟踪:

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)

我正在使用 OS X Snow Leopard 和 Java SDK 1.6.0_35(来自 Apple)。 JDK 和 JUnit 4 都在我的构建路径中。 Java 版本与该问题有关吗?

UPDATE:

好吧,我是个白痴,没有想到这一点。我安装了 Eclipse for C/C++ Developers,因为我必须用 C++ 做一些事情。但我还使用相同的实例通过 Android SDK 插件进行 Android 开发,并制作了一些小型 Java 应用程序。但我没有安装 Java 开发工具或 Java EE 开发人员工具。我现在安装了它们,JUnit 4 现在可以工作了。

我猜想其中一个工具是用于 JUnit 4 的。奇怪的是 JUnit 3 竟然能工作。 不管怎样,现在可以了。

不过还是谢谢大家的支持。


好吧,我是个白痴,没有想到这一点。我安装了 Eclipse for C/C++ Developers,因为我必须用 C++ 做一些事情。但我还使用相同的实例通过 Android SDK 插件进行 Android 开发,并制作了一些小型 Java 应用程序。但我没有安装 Java 开发工具或 Java EE 开发人员工具。我现在安装了它们,JUnit 4 现在可以工作了。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Eclipse JUnit 4 给出 NullPointerException 的相关文章

随机推荐