在VSCODE中使用Junit 5时找不到或加载主类

发布于 2025-02-06 08:59:57 字数 972 浏览 1 评论 0原文

在VSCODE中使用Junit 5时,我目前正在面临问题。

我注意到,一旦“ junit-platform-console-standalone-1.7.0-m1.jar”就在我项目的库文件夹中,我可以运行测试,但我无法再运行主要方法(“错误) :找不到或加载主类”)。一旦删除.jar,我就可以立即再次运行它。

当我将默认项目与无构建工具一起使用时,问题也会发生。

我创建了一个简单的测试类,并让.jar文件通过“ Testing” Explorer自动下载(启用Java测试按钮)。现在下载了.jar文件,测试可以正常工作,但主要方法不行。如果我将.jar从文件夹中删除,则主要方法再次工作,但显然测试AINT。

”测试类“

”

是否可以同时运行?先感谢您!

I am currently facing problems when using JUnit 5 in VSCode.

I noticed that as soon as the "junit-platform-console-standalone-1.7.0-M1.jar" is in my library folder within my project I can run my tests but I can not run my main method any more ("Error: Could not find or load main class"). As soon as I remove the .jar I can immediately run it again.

The problem also occurs when I use the default project with no-build tools.

I created a simple test class and let the .jar file automatically download via the "Testing" explorer (enable Java Tests Button). Now that the .jar file is downloaded, the tests work but the main method doesn't. If I remove the .jar out of the folder, the main method works again but obviously the tests aint.
Main class and project folder

Test class

settings.json file

Error Message

Any solutions so I can run both? Thank you in advance!

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

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

发布评论

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

评论(1

自控 2025-02-13 08:59:58

在不了解您的项目的情况下,这里有一些解决方法可能会有所帮助:

  1. 重新加载vs代码并运行 f1 - > 清洁Java语言服务器工作区
  2. 在您的aumination.json文件中添加mainclasssourcepath配置。
  3. 检查您的文件夹/文件名,并确保文件路径的通用英语。
  4. 如果您安装了 Code Runner 扩展名,这也可能导致问题。您可以尝试卸载它,然后 f1 - > 清洁Java语言服务器工作区

希望这对您有帮助。

Without knowing more about your project, here are a few workarounds that might help:

  1. Reload VS Code and run F1 -> Clean the java language server workspace.
  2. Add the mainClass and sourcePaths configuration in your launch.json file.
  3. Check your folder/file name and make sure the file path is in plain English.
  4. This can also cause problems if you have the Code Runner extension installed. You can try to uninstall it, then F1 -> Clean the java language server workspace.

Hope this helps you.

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