无法解析 junit 平台启动器 1.6.3 intellij

Hum*_*Bee 7 intellij-idea junit5

我正在尝试在 Intellij 中运行测试,该测试曾经在 Spring Boot 2.2.x 早期工作过。我最近升级到 spring boot 2.3.9。当我尝试从运行配置运行测试时,它不会运行测试并抛出错误:

“无法解析 junit 平台启动器 1.6.3 intellij”。

但是,如果我在 cli 中运行测试,它工作正常。

Ray*_*yon 40

我遇到了同样的问题“无法解析 junit 平台启动器 1.8.1”intellij。IntelJ版本:2021.3

在这里找到了答案并且它有效,不需要向 pom.xml 添加任何依赖项。

转到设置 >> HTTP 代理 >> 选择自动检测代理设置

在此输入图像描述


Hum*_*Bee 10

事实证明,为了在 IntelliJ 中运行 Junit5 测试,需要添加 junit5-platform-launcher 依赖项。

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

在 pom.xml 中显式添加此依赖项,它将解决问题。

<dependency>
     <groupId>org.junit.platform</groupId>
     <artifactId>junit-platform-launcher</artifactId>
     <scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)


raz*_*one 8

对于 IntelliJ Idea 2021.1,我修复了类似的问题:

    <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>
Run Code Online (Sandbox Code Playgroud)

也许更好的解决方法是:

<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>
Run Code Online (Sandbox Code Playgroud)

在 Jetbrains 问题跟踪器上找到了上述解决方案