英文:
"No junit.jar" error in Intellij when right clicking a folder, but not when running individual classes of tests
问题
我的Spring Boot应用程序有几个测试类。
右键单击一个测试类,并选择“运行XYZtest”选项,它可以正常工作。
但是,当选择包含该类的文件夹并选择“在com.example.my中运行测试”时,会出现找不到junit.jar的错误:
当使用mvn运行所有测试时,它们都可以正常运行。
根据一些建议,我专门在“库”部分中添加了junit.jar,但没有帮助:
英文:
My Spring boot application has several tests classes.
When right-clicking a test class, and selecting the option to Run XYZtest
it works with no problem.
But when selecting the folder that contains that class and selecting Run test in com.example.my
I get an error of No junit.jar:
When running all the tests from mvn they run with no problems.
Following some suggestions, I added the junit.jar
specifically in the Library
section, but it didn't help:
答案1
得分: 2
我遇到了这个问题,以下是我是如何解决的:
背景:
- SpringBoot应用程序
- 使用Maven管理多个模块
- 在根POM的
dependencyManagement
中添加junit
的Maven依赖项(而不是dependencies
,它们的区别可以在这里找到) - 打算测试根模块的子模块内的类或文件夹
注:如果您的情况与上述背景不符,此解决方案可能无法解决您的问题。
步骤:
英文:
I met this problem, this is how I soloved it:
Context:
- SpringBoot application
- Use maven to manage multiple modules
- Add
junit
's maven dependency in root POM'sdependencyManagement
(rather thandependencies
, their differences can be found here) - Intend to test class or folder inside one of the root module's child module
PS: If your situation does not match the context above, this solution may not solve your problem.
Steps
答案2
得分: 1
Spring Boot正在使用JUnit 5。如果你使用Spring Boot的初始装配器网站,你应该有一个依赖项像这样。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
你在你的测试中使用JUnit 4还是5?你可以尝试更新IntelliJ或JUnit插件,这可能会解决你的问题。
英文:
Spring boot is using JUnit 5. If you use the spring boot initializr website, you should have a dependency like this.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
Did you use JUnit 4 or 5 in your tests ? You can try to update IntelliJ or JUnit plugin, this may solve your problem.
答案3
得分: 0
我成功解决了这个问题,方法是在根目录下的pom.xml文件中添加了Junit Maven依赖。
英文:
I managed to solve the issue by adding the Junit Maven dependancy in the root pom.xml file.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论