【问题标题】:failed to resolve junit platform launcher 1.6.3 intellij无法解决 junit 平台启动器 1.6.3 intellij
【发布时间】: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


    【解决方案1】:

    事实证明,为了让 Junit5 测试在 IntelliJ 中运行,需要添加 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>
    

    【讨论】:

    • 如果你在项目中使用 gradle,这里是在 build.gradle 中添加的依赖:\ntestImplementation 'org.junit.platform:junit-platform-launcher:1.8.2'
    【解决方案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>
    

    Found the above solution on Jetbrains issue tracker

    【讨论】:

    • 但是如果我只想运行JUnit 5,为什么要添加junit-vintage-engine的依赖呢?
    【解决方案3】:

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

    我找到了答案here 并且有效,无需向 pom 添加任何依赖项。

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

    【讨论】:

      【解决方案4】:

      这是official way to do this

      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>
      <!-- ... -->
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-03
        • 1970-01-01
        • 1970-01-01
        • 2015-03-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多