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:
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.
I met this problem, this is how I soloved it:
Context:
junit
's maven dependency in root POM's dependencyManagement
(rather than dependencies
, their differences can be found here )PS: If your situation does not match the context above, this solution may not solve your problem.
Steps
I managed to solve the issue by adding the Junit Maven dependancy in the root pom.xml file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.