Java JUnit4 + Eclipse“启动期间发生内部错误”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1250505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JUnit4 + Eclipse "An internal error occurred during Launching"
提问by Mike
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.
我正在尝试在 Eclipse 3.4.2 上运行 JUnit4 测试用例,但它甚至还没有开始。我的构建路径和测试应用程序中有 junit-4.7.jar。
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
然后我从 Eclipse 执行“运行 JUnit 测试用例”,并收到一个带有此消息的错误对话框
"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?
是什么导致了这些 NullPointerExceptions?我究竟做错了什么?
采纳答案by Mike
I was able to fix this just by deleting the workspace and the Eclipse directory and starting over.
我可以通过删除工作区和 Eclipse 目录并重新开始来解决这个问题。
回答by OpenSource
Your code works fine for me.
你的代码对我来说很好。
Eclipse Version: 3.4.1 Build id: M20080911-1700
Eclipse 版本:3.4.1 构建 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.
我右键单击 .java 文件 RunAs JUnit Test。这表明问题是由 Eclipse 配置问题引起的,而不是代码问题。
回答by Stephen C
Have you looked in the Eclipse error log? You can see it by opening the "Error Log" view.
您是否查看过 Eclipse 错误日志?您可以通过打开“错误日志”视图来查看它。
http://help.eclipse.org/help32/topic/org.eclipse.pde.doc.user/guide/tools/views/error_log.htm
http://help.eclipse.org/help32/topic/org.eclipse.pde.doc.user/guide/tools/views/error_log.htm
回答by aryaxt
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 !!!
谢谢,这也解决了我的问题。当我删除旧模拟器并创建一个新模拟器时,问题就开始了。修复:就像 OP 所说的删除工作区一样,确保将项目保留在其中 :) 然后将它们导入回 Eclipse “听起来像很多工作”?花了我不到半分钟!!!
回答by Vassilis Papavassiliou
This worked for me:
这对我有用:
- create another copy of the test class (CopyOfUTest.java)
- run the copy to make sure it passes
- go into Run > Run Configurations
- under JUnit, find the run configurations for the original class and the copied class
- right click and delete the configuration of the original class
- rename the configuration of the copied class to the original configuration name
- delete the copied class from the project
- 创建测试类的另一个副本 (CopyOfUTest.java)
- 运行副本以确保它通过
- 进入运行>运行配置
- 在JUnit下,找到原类和复制类的运行配置
- 右键删除原类的配置
- 将复制的类的配置重命名为原始配置名称
- 从项目中删除复制的类
回答by myked
I encountered a similar problem but I am using Python. This is what I did to solve/avoid it:
我遇到了类似的问题,但我使用的是 Python。这就是我为解决/避免它所做的:
- Removed my .project file and the project from Eclipse.
- Created the project again.
- Everything was working.
- 从 Eclipse 中删除了我的 .project 文件和项目。
- 再次创建项目。
- 一切正常。
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.
问题似乎出在 .project 文件中,其中有一些对 CDT Builder 的引用,而在新的 .project 文件中却没有。
回答by Sam
None of the given answers here worked for me, so I ended up just installing and using InfiniTestinstead. It doesn't have this problem, and it also runs the tests automatically so I can focus on my work.
这里给出的答案都不适合我,所以我最终只是安装和使用InfiniTest。它没有这个问题,而且它还自动运行测试,所以我可以专注于我的工作。
回答by Apurva Sharma
If you are using Android and its associated plugins, then Android only supports JUnit 3.
如果您使用的是 Android 及其相关插件,则 Android 仅支持 JUnit 3。
I resolved the problem by selecting Test Runner as JUnit 3.
我通过选择 Test Runner 作为 JUnit 3 解决了这个问题。
In my class, JUnit 4 is added in the build path->libraries.
在我的课程中,JUnit 4 被添加到构建路径->库中。
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).
然后要运行测试文件,请转到:Run As -> Run Configurations 然后选择相应的 test.java 文件并相应地选择 Test Runner(无论是 JUnit 3 还是 4)。
回答by Joaquin De La Sierra
What worked for me after trying everything:
尝试一切后对我有用的方法:
- Go to help
- Install New Software
- Work with: Juno
- Programming languages (expand it)
- Install Java Development Tools
- Restart
- 去帮忙
- 安装新软件
- 合作:朱诺
- 编程语言(展开)
- 安装 Java 开发工具
- 重新开始
It works :)
有用 :)
回答by Eric Leschinski
This error In eclipse can be caused if you are also using the Android Development Kit plugins:
如果您还使用 Android 开发工具包插件,则可能会在 eclipse 中导致此错误:
"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".
如果您将普通 Java 项目加载到安装并启用了 android ADT 插件的 Eclipse 实例中,则可能会导致此问题。在这种情况下,Eclipse 会查找“Android”项目文件,但没有找到。所以它说:“NullPointerException”。
So to fix it, re-download Eclipse without the ADT Plugin: https://www.eclipse.org/downloads/
因此,要修复它,请重新下载没有 ADT 插件的 Eclipse:https: //www.eclipse.org/downloads/
Then re-import your project fresh. And the junit tests run without a problem.
然后重新导入您的项目。并且junit 测试运行没有问题。
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.
许多人讨厌 eclipse,因为它有神秘的错误信息。这就像我们回到了 1950 年代的打孔卡世界,那里没有错误消息。程序只是停止并发生未定义的行为。