Reputation: 6816
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:
Upvotes: 3
Views: 8636
Reputation: 1
I managed to solve the issue by adding the Junit Maven dependancy in the root pom.xml file.
Upvotes: 0
Reputation: 92
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
More Run/Debug
-> Modify Run Configuration
Upvotes: 3
Reputation: 2017
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.
Upvotes: 1