简体   繁体   English

导入org.junit.jupiter 无法解决

[英]The import org.junit.jupiter cannot be resolved

Hey its the first time i use JUnit with Java and i'm not sure how to set it up inside Visual studio Code.嘿,这是我第一次使用 JUnit 和 Java,我不知道如何在 Visual Studio Code 中设置它。 I tried to put Junit-4.13.jar inside my a lib file in the root directory but nothing changed.我试图将 Junit-4.13.jar 放在我的根目录下的 lib 文件中,但没有任何改变。 any ideas?有任何想法吗? I am on MacOS.我在 MacOS 上。

在此处输入图像描述 在此处输入图像描述 在此处输入图像描述 在此处输入图像描述

There were 2 main issues with this configuration:此配置存在两个主要问题:

  • JUnit 4 dependency jar was used while in the source code imports from JUnit 5 API were used JUnit 4 依赖 jar 被使用,而在源代码中从 JUnit 5 中使用 ZDB9742387183ACE1D6 导入

  • Tests resided in the same location as sources, while the dependencies defined via Gradle/Maven for tests limit the scope to src/test/java roots.测试与源位于同一位置,而通过 Gradle/Maven 为测试定义的依赖项将 scope 限制为src/test/java根。

In a non-Gradle project the issue was fixed by adding the proper JUnit 5 dependencies to the module.在非 Gradle 项目中,通过将正确的 JUnit 5 依赖项添加到模块来解决问题。

In the Gradle project the issue was fixed by moving the test class from src/main/java to src/test/java .在 Gradle 项目中,通过将测试 class 从src/main/java移动到src/test/java来解决问题。

Sample Gradle project is available on GitHub . Gradle 项目示例可在 GitHub 上获得

More details about using JUnit 5 can be found in the official documentation .有关使用 JUnit 5 的更多详细信息,请参阅官方文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM