【发布时间】:2021-05-24 15:42:54
【问题描述】:
我正在尝试在 Intellij 中运行测试,该测试曾经在 Spring Boot 2.2.x 中早期工作。我最近升级到了spring boot 2.3.9。当我尝试从运行配置运行测试时,它不会运行测试并抛出错误:
'无法解析 junit 平台启动器 1.6.3 intellij'。
但是,如果我在 cli 中运行测试,它工作正常。
【问题讨论】:
标签: intellij-idea junit5
我正在尝试在 Intellij 中运行测试,该测试曾经在 Spring Boot 2.2.x 中早期工作。我最近升级到了spring boot 2.3.9。当我尝试从运行配置运行测试时,它不会运行测试并抛出错误:
'无法解析 junit 平台启动器 1.6.3 intellij'。
但是,如果我在 cli 中运行测试,它工作正常。
【问题讨论】:
标签: intellij-idea junit5
事实证明,为了让 Junit5 测试在 IntelliJ 中运行,需要添加 junit5-platform-launcher 依赖项。
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>
【讨论】:
\ntestImplementation 'org.junit.platform:junit-platform-launcher:1.8.2'
对于 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>
【讨论】:
junit-vintage-engine的依赖呢?
我遇到了同样的问题“无法解析 junit 平台启动器 1.8.1”intellij。 IntellJ 版本:2021.3
我找到了答案here 并且有效,无需向 pom 添加任何依赖项。
转到设置 >> HTTP 代理 >> 选择自动检测代理设置
【讨论】:
Maven Surefire 和 Maven Failsafe 可以运行基于 JUnit 4 的测试 只要您配置测试范围,就可以与 Jupiter 测试一起 依赖于 JUnit 4 和 JUnit Vintage TestEngine 实现类似于以下。
<!-- ... --> <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> <!-- ... -->
【讨论】: