The import org.junit.jupiter cannot be resolved

自闭症网瘾萝莉.ら 提交于 2020-05-09 12:04:15

问题


Hey its the first time i use JUnit with Java and i'm not sure how to set it up inside Visual studio Code. I tried to put Junit-4.13.jar inside my a lib file in the root directory but nothing changed. any ideas? I am on MacOS.


回答1:


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

  • 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.

In a non-Gradle project the issue was fixed by adding the proper JUnit 5 dependencies to the module.

In the Gradle project the issue was fixed by moving the test class from src/main/java to src/test/java.

Sample Gradle project is available on GitHub.

More details about using JUnit 5 can be found in the official documentation.



来源:https://stackoverflow.com/questions/61615291/the-import-org-junit-jupiter-cannot-be-resolved

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!