无法解决 JUnit 平台启动器 1.6.3 的问题 Intellij。

26

我正在尝试在Intellij中运行测试,这些测试在Spring Boot 2.2.x中可以正常工作。但是我最近升级到了Spring Boot 2.3.9版本。当我尝试从运行配置中运行测试时,它不能运行测试并会抛出错误:

'failed to resolve junit platform launcher 1.6.3 intellij'。

然而,如果我在命令行界面中运行测试,就可以正常工作。

10个回答

50

1
如果您在项目中使用Gradle,这是要添加到build.gradle中的依赖项: \n testImplementation 'org.junit.platform:junit-platform-launcher:1.8.2' - Evandro

35

我遇到了同样的问题:“无法解决 junit platform launcher 1.8.1”在intellij中。 IntellJ版本:2021.3

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

前往设置 >> HTTP代理 >> 选择自动检测代理设置

输入图像描述


这种误导性的错误。所以 "failed to resolve" 基本上意味着无法连接到工件仓库 - 请检查代理设置。 - zmx
这就是它! - Ewurafua Plange

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>

也许一个更好的解决方案是:
<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>

在Jetbrains的问题追踪器上找到了以上解决方案


1
但是如果我只想运行JUnit 5,为什么要添加“junit-vintage-engine”的依赖项? - LHCHIN
如果你只需要运行JUnit5的测试,就不需要JUnit Vintage引擎。在我的情况下,我有一些JUnit4和JUnit5的混合测试,因此出现了问题并需要修复。 - razvanone

3
如果您没有直接的互联网连接,但有像artifactory这样的仓库管理器,则idea会尝试从中解析junit-platform-launcher。确保您已配置了到maven中央存储库(虚拟存储库)的镜像,并且该镜像的artifactory url在没有身份验证的情况下可以访问(在“Force Authentication”选项卡的设置中应取消勾选)。 还要检查idea代理设置,并根据需要为artifactory域配置例外。

1

请在IntelliJ IDEA设置中检查您的代理设置。我打开了代理并解决了问题。


0

删除.m2文件夹中的内容(如果有settings.xml文件,请勿删除),以便重新下载所有的JAR包和依赖项(包括IntelliJ无法解析的),此后它将再次正常工作,无需添加任何依赖项或更改代理配置。


0
我遇到了类似的问题。在我的情况下,我通过Intellij选项从主类创建了一个Test类。它自动导入了来自jupiter的@Test - import org.junit.jupiter.api.Test; 然后我改成了import org.junit.Test; 这样就解决了问题。

enter image description here


所以基本上导入你想要的Junit版本,并确保在pom.xml中正确配置?类似于Gyanendra Singh的回答。 - ryanwebjackson

0

我尝试在pom.xml中添加以下依赖项,对我有效。

<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
尝试在pom中添加此依赖项
<dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-launcher</artifactId>
        <scope>test</scope>
        <version>1.8.2</version>
    </dependency>

-1

这里是官方的方法

Maven Surefire and Maven Failsafe can run JUnit 4 based tests alongside Jupiter tests as long as you configure test scoped dependencies on JUnit 4 and the JUnit Vintage TestEngine implementation similar to the following.

<!-- ... -->
<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.2</version>
        </plugin>
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.22.2</version>
        </plugin>
    </plugins>
</build>
<!-- ... -->
<dependencies>
    <!-- ... -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.13</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.vintage</groupId>
        <artifactId>junit-vintage-engine</artifactId>
        <version>5.7.2</version>
        <scope>test</scope>
    </dependency>
    <!-- ... -->
</dependencies>
<!-- ... -->

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接