Sunday, January 26, 2020

[Solved] no tests found with test runner junit 5

We often get this error in Eclipse/STS while working with JUnit. As we know JUnit has released JUnit5 after successor of JUnit4. When we create Spring Boot starter project whose version is higher than 2.1.4.RELEASE then by default Spring adds the JUnit5 dependencies.

no tests found with test runner junit 5

It can have multiple solutions but as of now I am explaining one of the solution here. So you have to follow some steps. In a simple way this blog will tell you to use JUnit4 instead of Junit5 but later I will update for JUnit5 as well.


Step 1:
If you are using Spring Boot then by default Spring adds spring-boot-starter-test 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>
Here you need to remove or make comment the <exclusions>. Now if you will check in the Maven Dependency you will get JUnit4.
<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-test</artifactId>
 <scope>test</scope>
</dependency>

Step 2:
Goto the the package src/test/java and open one of the JUnit test class. You need to change then @Test annotation import from import org.junit.jupiter.api.Test; to import org.junit.Test;


Step 3:
Now open your one of the JUnit test class then right click. Then goto Run As -> Run Configurations. Now Inside the Test tab, there is an option Test runner. Change it to JUnit5 to JUnit4 then click on Run.

Run Configurations

Congrats! Now it will run your JUnit test. Feel free to comment or give feedback if required any modification.

Share this

1 Response to "[Solved] no tests found with test runner junit 5"