当我从 test.java 文件运行时,JUnit 测试不会运行

发布于 2024-12-11 15:58:57 字数 508 浏览 0 评论 0原文

我在使用 JUnit4 和 Eclipse 时遇到了一个相当奇怪的问题。

我有一个 Quaternion.java 文件和一个关联的 QuaternionTest.java。在包资源管理器中,我可以右键单击 QuaternionTest.java 文件和 Run-As JUnit 下的 (C) 图标。测试按预期运行。当我右键单击 QuaternionTest.java 文件并尝试运行测试时,出现以下错误:

An internal error occurred during: "Launching java".
Path must include project and resource name: /QuaternionTest.java

我是 Eclipse 和 JUnit 的新手,如果这应该是显而易见的,请原谅我。我尝试查看属性,但没有看到任何内容。另外,如果我从构建路径中排除 QuaternionTest.java,一切都会运行良好(当然,四元数测试除外)

任何想法都将受到高度赞赏。

I have a rather odd problem w/ JUnit4 and Eclipse.

I have a Quaternion.java file, and an associated QuaternionTest.java. In the package explorer, I can right click on the (C) icon under the QuaternionTest.java file and Run-As JUnit. The test runs as expected. When I right click on the QuaternionTest.java file and try to run the test, I get the following error:

An internal error occurred during: "Launching java".
Path must include project and resource name: /QuaternionTest.java

I'm new to Eclipse and JUnit, so forgive me if this is supposed to be obvious. I've tried looking at the properties and don't see anything. Also, if I exclude QuaternionTest.java from my build path, everything runs fine (except, of course, the Quaternion tests)

Any ideas would be most appreciated.

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

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

发布评论

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

评论(2

风尘浪孓 2024-12-18 15:58:57

如果没有完整的环境,此类问题总是很难调试,但听起来您的运行配置已损坏或与您的类不匹配或类似的东西。尝试删除运行配置并重试。

当您选择 Run As JUnit 时,Eclipse 将创建特定于您的 JUnit 类的运行配置。

要解决此问题,请在 Eclipse 中打开“运行”->“运行配置”。在左侧列表中,找到适用于 QuaternionTest 的运行配置,确保它是 JUnit 部分中的运行配置。删除它(右键单击,选择删除)。然后再试一次。

在此处输入图像描述

This sort of problem is always difficult to debug without your full environment, but it sounds like you have a Run Configuration which is corrupted or doesn't match your classes or something like that. Try deleting the Run Configuration and retrying.

When you select Run As JUnit, Eclipse creates a Run Configuration specific to your JUnit class.

To fix this, in Eclipse, open Run->Run Configuration. In the list at the left, find the run configuration that applies to QuaternionTest, make sure it's the Run Configuration in the JUnit section. Delete it (right click, select delete). Then try again.

enter image description here

叹倦 2024-12-18 15:58:57

我处理这个问题一个小时,最后我通过运行配置-> JUnit-> yourTest 来解决它。在您的测试设置中更改测试运行程序并且它可以工作。

I dealt with this problem for an hour and finally I got it worked by going to run configuration->JUnit->yourTest. In your test setting change the test runner and it works.

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