问题描述
嘿,这是我第一次将JUnit与Java结合使用,但我不确定如何在Visual Studio Code中对其进行设置.我试图将Junit-4.13.jar放在根目录下的lib文件中,但没有任何更改.有任何想法吗?我在MacOS上.
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.
推荐答案
此配置存在2个主要问题:
There were 2 main issues with this configuration:
-
使用了JUnit 4依赖罐,而在源代码中则使用了从JUnit 5 API导入的
JUnit 4 dependency jar was used while in the source code imports from JUnit 5 API were used
测试与源代码位于同一位置,而通过Gradle/Maven为测试定义的依赖项将范围限制为src/test/java
根.
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项目中,通过向模块添加适当的JUnit 5依赖关系来解决此问题.
In a non-Gradle project the issue was fixed by adding the proper JUnit 5 dependencies to the module.
在Gradle项目中,通过将测试类从src/main/java
移到src/test/java
,解决了该问题.
In the Gradle project the issue was fixed by moving the test class from src/main/java
to src/test/java
.
Sample Gradle项目可用在GitHub上.
Sample Gradle project is available on GitHub.
有关使用JUnit 5的更多详细信息,请参见在官方文档中.
More details about using JUnit 5 can be found in the official documentation.
这篇关于导入org.junit.jupiter无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!