JUnit4 + Eclipse“启动期间发生内部错误”
我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
尝试一切后对我有用的方法:
它有效:)
What worked for me after trying everything:
It works :)
我只需删除工作区和 Eclipse 目录并重新开始即可解决此问题。
I was able to fix this just by deleting the workspace and the Eclipse directory and starting over.
这对我有用:
This worked for me:
这里给出的答案都不适合我,所以我最终只是安装和使用 InfiniTest 。 它没有这个问题,而且它还会自动运行测试,这样我就可以专注于我的工作。
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 错误日志吗? 您可以通过打开“错误日志”视图来查看它。
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
如果您还使用 Android 开发工具包插件,则可能会在 Eclipse 中导致此错误:
如果您将普通 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:
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.
谢谢这也解决了我的问题。
当我删除旧模拟器并创建新模拟器时,问题就开始了。
修复:就像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 !!!
如果您使用的是 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).
你的代码对我来说效果很好。
蚀
版本: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.
我遇到了类似的问题,但我使用的是Python。 这就是我解决/避免它的方法:
问题似乎出在 .project 文件中,其中有一些对 CDT Builder 的引用,但新的 .project 文件中没有。
I encountered a similar problem but I am using Python. This is what I did to solve/avoid it:
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.