23

I am trying to run tests in Intellij which used to work earlier in spring boot 2.2.x. I recently upgraded to spring boot 2.3.9. When I try to run the test from Run Configurations, it doesn't run the test and throws the error:

'failed to resolve junit platform launcher 1.6.3 intellij'.

However if I run the test in cli, it works fine.

serv-inc
  • 35,772
  • 9
  • 166
  • 188
Humble Bee
  • 1,130
  • 2
  • 12
  • 19

8 Answers8

45

It turns out that, junit5-platform-launcher dependency needs to be added in order for Junit5 tests to run in IntelliJ.

https://youtrack.jetbrains.com/issue/IDEA-231927?_ga=2.5997872.2063517257.1613993298-1098513328.1597974168

https://junit.org/junit5/docs/current/user-guide/#running-tests-ide-intellij-idea

Add this dependency explicitly in pom.xml, and it will solve the issue.

<dependency>
     <groupId>org.junit.platform</groupId>
     <artifactId>junit-platform-launcher</artifactId>
     <scope>test</scope>
</dependency>
Humble Bee
  • 1,130
  • 2
  • 12
  • 19
  • 1
    If you use gradle in your project, here is the dependency to add inside build.gradle: `\n` `testImplementation 'org.junit.platform:junit-platform-launcher:1.8.2'` – Evandro Dec 07 '21 at 14:39
32

I was facing same issue "failed to resolve junit platform launcher 1.8.1" intellij. IntellJ version: 2021.3

I found answer here and it worked, no need to add any dependency to pom.

Go to settings >> HTTP Proxy >> choose auto-detect proxy settings

enter image description here

Rayon
  • 661
  • 8
  • 9
8

For IntelliJ Idea 2021.1, I fixed a similar problem with:

    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-launcher</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.vintage</groupId>
        <artifactId>junit-vintage-engine</artifactId>
        <scope>test</scope>
    </dependency>

Maybe an even better fix is:

<dependencyManagement>
    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.junit/junit-bom -->
        <dependency>
            <groupId>org.junit</groupId>
            <artifactId>junit-bom</artifactId>
            <version>5.7.1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Found the above solution on Jetbrains issue tracker

razvanone
  • 1,351
  • 18
  • 27
  • 1
    But if I want to run JUnit 5 only, why should I add the dependency of `junit-vintage-engine`? – LHCHIN Aug 26 '21 at 09:33
  • If you need to run only junit5 tests, you don't need junit-vintage-engine. In my case, I had a mixture of junit4 and junit5 tests, therefore the problem and the need for a fix. – razvanone Jul 20 '23 at 12:38
3

If you have no direct internet connection but a repository manager like artifactory, idea tries to resolve junit-platform-launcher from there. Make sure u have a mirror to maven central repository (virtual repository) configured and the artifactory url to this mirror is accessible WITHOUT authentication (in the settings for the repo "Force Authentication" should be unchecked). Check also the idea proxy settings and if needed, configure an exception for the artifactory domain.

Wishmaster
  • 51
  • 5
1

Check your proxy settings in IntelliJ Idea settings. I turned ON the proxy and it solved the problem.

0

I tried Adding following dependencies in the pom.xml, it worked for me.

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${version.junit.jupiter}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${version.junit.jupiter}</version>
<scope>test</scope>
</dependency>
0

Try adding this dependency in pom

<dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-launcher</artifactId>
        <scope>test</scope>
        <version>1.8.2</version>
    </dependency>
Dhiraj Surve
  • 310
  • 2
  • 5
0

I have faced similar problem. In my case I created Test class from main class via Intellij option. It automatically imported @Test from jupiter - import org.junit.jupiter.api.Test; Then I changed to import org.junit.Test; which resolved the issue.

enter image description here

Augustin
  • 25
  • 4
  • So basically import the version of Junit you want, and ensure it's configured properly in pom.xml? Similar to Gyanendra Singh's answer – ryanwebjackson Jul 30 '23 at 21:42