JUnit4 + Eclipse“启动期间发生内部错误”

发布于 2024-07-30 11:04:07 字数 613 浏览 4 评论 0原文

我正在尝试在 Eclipse 3.4.2 上运行 JUnit4 测试用例,但它甚至还没有启动。 我的构建路径和测试应用程序中有 junit-4.7.jar。

这是一个简单的例子,说明了我的问题

package test;
import org.junit.Before;
import org.junit.Test;

public class UTest {    
    @Test
    public void test() {
    }

    @Before
    public void setUp() throws Exception {
    }
}

这编译得很好

然后我从 Eclipse 中执行“运行 JUnit 测试用例”,我得到一个带有此消息的错误对话框

"Launching UTest' has encountered a problem
An internal error occurred during: "Launching UTest".
java.lang.NullPointerException

是什么导致了这些 NullPointerExceptions? 我究竟做错了什么?

I'm trying to run JUnit4 test cases on Eclipse 3.4.2 but it's not even starting for me. I have the junit-4.7.jar in my build path and the test application.

Here is a simple example that illustrates my problem

package test;
import org.junit.Before;
import org.junit.Test;

public class UTest {    
    @Test
    public void test() {
    }

    @Before
    public void setUp() throws Exception {
    }
}

This compiles fine

Then I do "Run JUnit Test case" from Eclipse and I get an error dialog with this message

"Launching UTest' has encountered a problem
An internal error occurred during: "Launching UTest".
java.lang.NullPointerException

What causes these NullPointerExceptions? What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

许一世地老天荒 2024-08-06 11:04:07

尝试一切后对我有用的方法:

  1. 去帮助
  2. 安装新软件
  3. 使用: Juno
  4. 编程语言(展开它)
  5. 安装 Java 开发工具
  6. 重新启动

它有效:)

What worked for me after trying everything:

  1. Go to help
  2. Install New Software
  3. Work with: Juno
  4. Programming languages (expand it)
  5. Install Java Development Tools
  6. Restart

It works :)

踏雪无痕 2024-08-06 11:04:07

我只需删除工作区和 Eclipse 目录并重新开始即可解决此问题。

I was able to fix this just by deleting the workspace and the Eclipse directory and starting over.

何必那么矫情 2024-08-06 11:04:07

这对我有用:

  1. 创建测试类的另一个副本 (CopyOfUTest.java)
  2. 运行该副本以确保它通过
  3. 进入 Run > > JUnit下的Run Configurations
  4. ,找到原类和复制的类的运行配置
  5. 右键删除原类的配置
  6. 将复制的类的配置重命名为原配置名称
  7. 从项目中删除复制的类

This worked for me:

  1. create another copy of the test class (CopyOfUTest.java)
  2. run the copy to make sure it passes
  3. go into Run > Run Configurations
  4. under JUnit, find the run configurations for the original class and the copied class
  5. right click and delete the configuration of the original class
  6. rename the configuration of the copied class to the original configuration name
  7. delete the copied class from the project
陌上青苔 2024-08-06 11:04:07

这里给出的答案都不适合我,所以我最终只是安装和使用 InfiniTest 。 它没有这个问题,而且它还会自动运行测试,这样我就可以专注于我的工作。

带有 Infinitest 的 Eclipse 在“问题”选项卡中显示红色“测试失败”状态消息和相应的断言错误

None of the given answers here worked for me, so I ended up just installing and using InfiniTest instead. It doesn't have this problem, and it also runs the tests automatically so I can focus on my work.

Eclipse with Infinitest showing a red "tests failed" status message and the corresponding assertion error in the "Problems" tab

难得心□动 2024-08-06 11:04:07

您查看过 Eclipse 错误日志吗? 您可以通过打开“错误日志”视图来查看它。

http:// help.eclipse.org/help32/topic/org.eclipse.pde.doc.user/guide/tools/views/error_log.htm

Have you looked in the Eclipse error log? You can see it by opening the "Error Log" view.

http://help.eclipse.org/help32/topic/org.eclipse.pde.doc.user/guide/tools/views/error_log.htm

幽梦紫曦~ 2024-08-06 11:04:07

如果您还使用 Android 开发工具包插件,则可能会在 Eclipse 中导致此错误:

"Launching UTest' has encountered a problem
    An internal error occurred during: "Launching UTest".
    java.lang.NullPointerException

如果您将普通 Java 项目加载到安装并启用了 Android ADT 插件的 Eclipse 实例中,则可能会导致该错误。 在这种情况下,Eclipse 会查找“Android”项目文件,但没有找到任何文件。 所以它说:“NullPointerException”。

因此,要修复此问题,请重新下载不带 ADT 插件的 Eclipse: https://www.eclipse.org/downloads/

然后重新导入您的项目。 并且 junit 测试运行没有问题。

许多人讨厌 eclipse,因为它有神秘的错误消息。 这就像我们回到了 1950 年代的打孔卡世界,那里没有错误消息。 程序只是停止并发生未定义的行为。

This error In eclipse can be caused if you are also using the Android Development Kit plugins:

"Launching UTest' has encountered a problem
    An internal error occurred during: "Launching UTest".
    java.lang.NullPointerException

Can be caused if you are loading a normal Java project into an Eclipse instance with android ADT plugins installed and enabled. In this situation, Eclipse looks for "Android" project files, and doesn't find any. So it says: "NullPointerException".

So to fix it, re-download Eclipse without the ADT Plugin: https://www.eclipse.org/downloads/

Then re-import your project fresh. And the junit tests run without a problem.

Many people hate eclipse for it's enigmatic error messages. It's like we are back in the 1950's punch card world, where there are no error messages. The program just halts and undefined behavior occurs.

指尖上得阳光 2024-08-06 11:04:07

谢谢这也解决了我的问题。
当我删除旧模拟器并创建新模拟器时,问题就开始了。
修复:就像OP所说的删除工作区,确保将项目保留在其中:)
然后将它们导入回 eclipse
“听起来工作量很大”?
我花了不到半分钟!

Thanks that solved my problem too.
The problem started when i removed an old simulator, and created a new one.
Fix: Like the OP says remove the workspace, make sure to keep the projects inside it :)
then import them back to eclipse
"Sound like a lot of work" ?
Took me less than half a minute !!!

浮云落日 2024-08-06 11:04:07

如果您使用的是 Android 及其相关插件,则 Android 仅支持 JUnit 3。

我通过选择 Test Runner 作为 JUnit 3 解决了该问题。

在我的课程中,JUnit 4 添加在构建路径 -> 库中。

然后运行测试文件,转到:Run As -> Run Configurations 然后选择相应的 test.java 文件并相应选择 Test Runner(无论是 JUnit 3 还是 4)。

If you are using Android and its associated plugins, then Android only supports JUnit 3.

I resolved the problem by selecting Test Runner as JUnit 3.

In my class, JUnit 4 is added in the build path->libraries.

Then to run the test file, go to: Run As -> Run Configurations then select the corresponding test.java file and select Test Runner accordingly(whether it is JUnit 3 or 4).

请止步禁区 2024-08-06 11:04:07

你的代码对我来说效果很好。


版本:3.4.1
构建 ID:M20080911-1700

我右键单击 .java 文件 RunAs JUnit Test。 这表明问题是由 Eclipse 配置问题引起的,而不是代码问题。

Your code works fine for me.

Eclipse
Version: 3.4.1
Build id: M20080911-1700

I right click on the .java file RunAs JUnit Test. This would indicate the problem is caused by an Eclipse configuration problem, not a code problem.

腻橙味 2024-08-06 11:04:07

我遇到了类似的问题,但我使用的是Python。 这就是我解决/避免它的方法:

  1. 从 Eclipse 中删除了我的 .project 文件和项目。
  2. 再次创建项目。
  3. 一切正常。

问题似乎出在 .project 文件中,其中有一些对 CDT Builder 的引用,但新的 .project 文件中没有。

I encountered a similar problem but I am using Python. This is what I did to solve/avoid it:

  1. Removed my .project file and the project from Eclipse.
  2. Created the project again.
  3. Everything was working.

The problem seemed to be in the .project file where there were some references to CDT Builder and were not there in the new .project file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文