riorio
riorio

Reputation: 6816

"No junit.jar" error in Intellij when right clicking a folder, but not when running individual classes of tests

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:

enter image description here

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

Answers (3)

Stephen Onyonge
Stephen Onyonge

Reputation: 1

I managed to solve the issue by adding the Junit Maven dependancy in the root pom.xml file.

Upvotes: 0

SteveHu
SteveHu

Reputation: 92

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's dependencyManagement(rather than dependencies, 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

  1. right click at the class or folder you want to test:
    enter image description here
  2. Choose More Run/Debug -> Modify Run Configuration
  3. Change the module option to the one you want to test from root module enter image description here

Upvotes: 3

Cyril G.
Cyril G.

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

Related Questions