【问题标题】:Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactoryEclipse NoClassDefFoundError for LauncherFactory 未找到使用 JUnit 5 的测试
【发布时间】:2017-10-12 19:44:33
【问题描述】:

问题

每当我运行我的项目 JUnit 测试(使用 JUnit 5 和 Java 9 和 Eclipse Oxygen 1.a)时,我都会遇到 eclipse 找不到任何测试的问题。

说明

在运行配置下,eclipse甚至找不到带有@Test注解的方法,而是只显示“(所有方法)”。 下图希望能更好地了解我的设置:

控制台输出:

java.lang.NoClassDefFoundError: org/junit/platform/launcher/core/LauncherFactory
    at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.<init>(JUnit5TestLoader.java:31)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.base/java.lang.Class.newInstance(Unknown Source)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createRawTestLoader(RemoteTestRunner.java:368)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createLoader(RemoteTestRunner.java:363)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:307)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.init(RemoteTestRunner.java:222)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.launcher.core.LauncherFactory
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
    ... 11 more

到目前为止我尝试了什么

我已经试过了

  • 从构建路径中删除测试文件夹并重新添加。
  • 将鼠标悬停在带有@Test 注释的方法上开始测试,然后单击“作为 JUnit 测试运行”。
  • 从 Buildpath 中移除 JUnit 并重新添加
  • 重启eclipse
  • 我还将项目整个项目从一台机器移动到另一台机器,并使用那里提供的 eclipse 安装进行了尝试
  • 重命名测试方法。
  • 重新输入@Test 注释

其中一些步骤can be found here,但最终问题仍然存在。

【问题讨论】:

标签: java eclipse junit junit5


【解决方案1】:

我通过右键单击测试并选择“运行配置”并将“测试运行器:”选项更改为“JUnit 4”来解决此问题,如下所示:

我再次运行了测试,它成功了。

【讨论】:

  • 在使用 JUnit5 时在运行配置中选择“JUnit4”很有趣。当我处理一个大项目时,我不会把它称为一个可以依赖的好解决方案。
  • 我也觉得这个解决方案很可疑,它甚至没有解释为什么会这样以及可能会冒什么风险。
  • 如果这样做没有为您解决问题,请转到同一窗口上的类路径选项卡并将 JUnit 添加到引导库。
  • 谢谢;选择 JUnit 4 解决了我的问题。目前,这是解决问题的最简单方法。
  • 在我看来这种侵入性较小的解决方案,即无需修改源代码。
【解决方案2】:

我对 STS 3.9.1 也有同样的问题。这似乎是一个 Eclipse 错误,但是,要解决此问题,您可以将测试依赖项 junit-platform-launcher 添加到您的项目 (https://mvnrepository.com/artifact/org.junit.platform/junit-platform-launcher)

这就是我为使用 gradle 的项目所做的:

dependencies {
    // other stuff here

    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "5.${junit5MinorVersion}"
    testCompile group: 'org.junit.platform', name: 'junit-platform-launcher', version: "1.${junit5MinorVersion}"
}

gradle.properties 文件:

junit5MinorVersion=1.0

如果您在使用 IntelliJ IDEA 时看到此异常,我相信同样适用。

【讨论】:

  • 如果使用 gradle 通常会转到build.gradle。如果您使用的是 maven,则为 pom.xml。 maven 的格式虽然不同。
  • 为我解决了这个问题。谢谢!
  • 这是要进入 的 pom.xml sn-p: org.junit.jupiterjunit-jupiter-engine5.1.0testorg.junit.platformjunit-platform-launcher1.1.0 test
  • 仍然添加 junit-platform 1.1.0 对我不起作用。它显示相同的消息“没有使用 JUnit 5 的测试运行器找到测试”“
  • @PSatishPatro 添加上述内容后。您需要为该 Junit 测试用例运行配置,然后转到 Classpath 选项卡-> Advanced-> Add Library-> OK-> Junit-> Finish。然后继续运行它。这将在 Junit 执行期间添加库
【解决方案3】:

就我而言,问题出在我自己身上,没有像 Eclipse 这样的 IDE。我已经导入了 JUnit 4 测试类。

所以不要导入这个:

import org.junit.Test  // JUnit 4

但是一定要导入那个:

import org.junit.jupiter.api.Test // JUnit 5

【讨论】:

  • 我在 JUnit 4 和 5 之间切换,因为当前项目正在使用 JUnit 5,但是当向 Hibernate 等报告错误时,我需要切换到 JUnit 4。我最终不小心混合了导入。 ?‍♂️
  • 这个答案需要更多的支持!
【解决方案4】:

简单修复:(添加 JUnit 5 库)

说明:

  • 右键项目->构建路径->配置构建路径
  • 在弹出窗口中 -> 添加库 -> JUnit -> JUnit 5 -> 完成 -> 应用
  • 您应该会看到 JUnit 5 库(及其 jar)已添加到您的项目中
  • 右键项目->Maven->更新项目->确定

【讨论】:

  • GRADLE FIX: (Add JUnit 5 Library) INSTRUCTIONS: * 右击项目 -> 构建路径 -> 配置构建路径 * 在弹出窗口中 -> 添加库 -> JUnit -> JUnit 5 -> 完成 -> 应用 * 你应该看到 JUnit 5 库(及其 jars)添加到你的项目 * 右键单击​​项目 -> Gradle -> 刷新 Gradle 项目 * 右键单击​​项目 -> 运行方式 -> Junit Test
  • 这应该被接受,谢谢@JerryCarney
【解决方案5】:

您遇到了 Eclipse bug 525948,该问题已得到修复,将在 2018 年 3 月 21 日即将发布的 Oxygen.3 (4.7.3) 版本中发布。

作为解决方法,将您的测试代码放在一个单独的项目中并将被测项目添加到模块路径中,但不要将module-info.java 添加到您的测试项目中。使用您的项目、类和模块命名,它应该如下所示:

另见my video that shows Java 9 and JUnit 5 in Eclipse Oxygen.1a in action

【讨论】:

  • @nullpointer 我的意思是创建一个非模块化的新 Java 项目(没有 module-info.java)。在 Eclipse 中,Java 项目只有一个输出文件夹,因此它只能包含一个或不包含一个 module-info.java。但是即使项目不是模块化的(没有module-info.java),您也可以将模块添加到项目的模块路径中。
  • @ShadowDragon 这个 hack 的缺点是我们需要为测试类使用不同的包名,因此不能进行包私有测试
  • 我刚安装了 Oxygen.3 (4.7.3) 问题依然存在。
  • @chomp 如果您有 2018-09,即使症状看起来相似,这也是一个不同的问题。如果没有找到测试,这主要是由于类路径/模块路径不正确(Project > Properties: Java Build Path)。
  • @howlger 谢谢。升级到最新版本后,这个问题就消失了。再次感谢您的帮助:)。
【解决方案6】:

到目前为止,答案并未解决与不一定使用 Eclipse 的其他人共享代码的问题。这是一个提议。关键是使用maven profile来解决Eclipse Case。

假设您在 pom 中定义了一个属性 junit5.version,例如:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <junit5.version>5.1.1</junit5.version>
</properties>

然后在profiles 部分添加以下内容:

<profiles>
    <profile>
        <id>eclipse</id>
        <dependencies>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-engine</artifactId>
            </dependency>
            <dependency>
                <groupId>org.junit.platform</groupId>
                <artifactId>junit-platform-launcher</artifactId>
            </dependency>
        </dependencies>
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-engine</artifactId>
                    <version>${junit5.version}</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-launcher</artifactId>
                    <version>1.1.1</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
    </profile>
</profiles>

在此之后您要做的就是在本地 Eclipse 中选择配置文件:右键单击您的项目并选择 Maven &gt; Select Maven Profiles...(或点击 Ctrl + Alt + P),然后检查我们刚刚创建的“eclipse”配置文件。

这样你就完成了。您的 Eclipse 将按预期运行 Junit 5 测试,但您添加的配置不会污染其他构建或其他 IDE

【讨论】:

    【解决方案7】:

    用 JUnit Jupiter (v.5.5.1) 添加这个 maven 依赖可以解决这个问题。

    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-launcher</artifactId>
        <version>1.5.1</version>
        <scope>test</scope>
    </dependency>
    

    【讨论】:

    • 我为 Spring Boot 2.x 创建了一个 JAR 项目,它引入了 JUnit 5。我添加了这个依赖项,它似乎已经修复了它。谢谢!
    • 这个解决方案也解决了我在 STS IDE 中的问题。
    【解决方案8】:

    没有任何解决方案有帮助:

    问题在于 Eclipse 2018-12 支持 JUnit 5.3.1。如果您使用之前的版本启动它,它将失败。

    所以请确保您至少使用 5.3.1。

    5.4.0 也可以。

    如果你的父 pom 是 Spring Boot,你需要确保(在依赖管理中)junit-jupiter-api 设置为相同的版本。您不需要 junit-platform-runner 或 -launcher

    【讨论】:

    • 感谢您的提示。我正在使用 2019-3 并添加属性 &lt;junit-jupiter.version&gt;5.4.1&lt;/junit-jupiter.version&gt; 以覆盖 Spring boot (2.1.3.RELEASE) 中使用的版本。
    • 这是为我修复它的那个。我删除了 -launcher 依赖项,它开始工作。 (eclipse 2019-09 和 junit 5.4.2)
    • 这个解决方案也适用于我。但是,就我而言,我从 5.3.1 更改为 5.5.1,将 junit-platform-engine 更改为 1.5.1。
    • 这为我解决了问题。在 Eclipse 2020-03 中,测试不是从 junit 版本 5.5.2 开始,而是从 5.6.0 开始。作为您答案的一般更新:可能需要至少使用 eclipse 使用的 junit 版本。
    【解决方案9】:

    Andrii Karaivanskyi's answer 之后是 Maven POM 声明:

    <properties>
        ...
        <junit-jupiter.version>5.2.0</junit-jupiter.version>
        <junit-platform.version>1.2.0</junit-platform.version>
        ...
    </properties>
    
    <dependencies>
        ...
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit-jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
            <version>${junit-platform.version}</version>
            <scope>test</scope>
        </dependency>
        ...
    </dependencies>
    

    更新

    根据Alexander Wessel 的评论,您可以按照his answer 中的说明使用org.junit:junit-bom 来提问Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactory

    【讨论】:

    • 不要声明 jupiter 和平台版本的属性,use the BOM instead。基本上使用scope=import type=pom在dependencyManagement标签中添加对BOM的依赖,然后在测试范围内将依赖添加到junit-platform-launcher和junit-jupiter-engine,在依赖部分不提供版本 . BOM 将始终确保您在类路径中只有一个版本的 JUnit Platform 和 Jupiter,并且各个版本都是预期的版本(例如 5.2.0 和 1.2.0)。
    • @AlexanderWessel 我没有 BOM。这只是一个示例摘录,无论它在哪里,都必须使用 Maven 声明依赖项。
    • 这不是您拥有(或者更确切地说是您的项目拥有)BOM 本身。我在解释,通过导入 JUnit 5 提供的BOM ,您可以确保Junit Jupiter 和Junit Platform 版本兼容,并且您不需要声明版本在各个依赖项中,因此也不再需要声明版本属性。需要明确的是:您的示例 确实 工作正常。但是导入 JUnit BOM 更优雅一些(以我的拙见),并且在某些情况下更安全。
    【解决方案10】:

    我实际上使用的是 spring-tool-suite-4-4.5.1,当我想运行一个测试类时我遇到了这个错误。 解决方案是在库中添加“java build path”、“junit5”

    【讨论】:

    • 我最初使用了这个解决方案并且它有效,然后我阅读了其他答案,我发现“正确”的答案是@armin.miedl's。我从构建路径中删除了 JUnit 5 库,并将 Test 注释导入替换为正确的。
    【解决方案11】:

    仅供参考,“未找到使用 junit5 的测试”的另一个原因是(无意或有意)将测试用例声明为“私有”:

    // Example of test case that doesn't get included
    @Test
    private void testSomeMethod() {
    }
    

    他们需要公开。

    【讨论】:

      【解决方案12】:

      我也遇到了同样的问题,你只需要添加库,Junit 库已经随 Eclipse 一起提供了,所以你只需要按照下面的操作

      构建路径 > 配置构建路径 > 库 > 添加库 > JUnit > 下一步 > 完成

      对我有用

      【讨论】:

      • 它在 Eclipse 中运行良好。版本:2020-06 (4.16.0) 版本号:20200615-1200
      【解决方案13】:

      从一开始,错误消息就告诉您找不到类:NoClassDefFoundError,这意味着到 junit 的路径是问题。

      1. 按右键单击项目文件夹并选择属性或选择项目文件夹并按组合 cmd + i。

      2. 从“Java 构建路径”列表中选择。

      3. 选择“库”标签
      4. 如果将 JUnit 5(或 JUnit 4)添加到“Modulepath”,请选择“JUnit 5”并按 Remove。
      5. 选择“类路径”,按“添加库...”。
      6. 从打开的“添加库”窗口中,选择 JUnit,按下一步。
      7. 选择您需要的 JUnit 库版本,然后按完成。

      就是这样。尝试再次运行测试。

      【讨论】:

        【解决方案14】:

        替换:

        import org.junit.Test;
        

        与:

        import org.junit.jupiter.api.Test;
        

        【讨论】:

          【解决方案15】:

          我在创建一个新的 TestCase 后遇到了同样的问题:Eclipse -> New -> JUnit Test Case。它创建一个没有访问级别修饰符的类。我可以通过在 class 关键字之前放置一个 public 来解决问题。

          【讨论】:

          【解决方案16】:

          正如每个人都告知这是 IDE 错误,我在 EclipseSTS 中进行了尝试。在这两种情况下,它都失败了。

          作为一种解决方法,我已通过修改 pom.xml 文件进行修复,如下所示。

          我已经添加了这两个maven依赖junit-jupiter-enginejunit-platform-launcher

          pom.xml

          <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
              <dependency>
                  <groupId>org.junit.jupiter</groupId>
                  <artifactId>junit-jupiter-engine</artifactId>
                  <version>${junit-jupiter.version}</version>
                  <scope>test</scope>
              </dependency>
          
              <!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform launcher -->
              <dependency>
                  <groupId>org.junit.platform</groupId>
                  <artifactId>junit-platform-launcher</artifactId>
                  <version>${junit-platform.version}</version>
                  <scope>test</scope>
              </dependency>
          </dependencies>
          

          另外,请确保在属性标签中添加两个 maven 依赖项的版本。

          <properties>
              <java.version>1.8</java.version>
              <junit-jupiter.version>5.2.0</junit-jupiter.version>
              <junit-platform.version>1.2.0</junit-platform.version>
          </properties>
          

          【讨论】:

          • 添加 junit-platform-launcher 依赖项为我解决了这个问题。谢谢
          【解决方案17】:

          你应该知道:

          junit4 中的@Before 与@Test 一起使用:“import org.junit.Test

          @BeforeEach 来自 Junit5 与:“import org.junit.jupiter.api.Test

          所以请确保您使用的是来自同一版本 Junit 的导入,否则我猜它不会工作。

          【讨论】:

            【解决方案18】:

            使用 STS 3.9.1 我遇到了同样的问题。但是,目前我不需要任何新的 JUnit5 功能,所以我尝试强制使用旧版本。如果使用 maven,您可以在 pom.xml 中添加以下依赖项:

            <dependency>
                <groupId>org.junit.platform</groupId>
                <artifactId>junit-platform-launcher</artifactId>
                <version>${junit.platform.version}</version>
                <scope>test</scope>
            </dependency>
            
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-engine</artifactId>
                <version>${junit.jupiter.version}</version>
                <scope>test</scope>
            </dependency>
            
            <dependency>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
                <version>${junit.vintage.version}</version>
                <scope>test</scope>
            </dependency>
            

            这对我有用(至少只要我不明确需要 JUnit5)。

            【讨论】:

            • 如果您使用的是 JUnit5,为什么要添加“org.junit.vintage”?它只是为了向后兼容(比如使用旧的 JUnit)AFAIK。
            • 因为那个项目和 STS 3.9.1 我不能/没有使用 JUnit5,而是 JUnit4。
            【解决方案19】:

            我正在使用 eclipse 2019-09。

            我必须将 junit-bom 版本更新到至少 5.4.0。我以前有 5.3.1,这导致了 OP 的相同症状。

            我现在的配置是:

                <dependencyManagement>
                    <dependencies>
                        <dependency>
                            <groupId>org.junit</groupId>
                            <artifactId>junit-bom</artifactId>
                            <version>5.5.2</version>
                            <type>pom</type>
                            <scope>import</scope>
                        </dependency>
                    </dependencies>
                </dependencyManagement>
            

            【讨论】:

            • 另一种选择是将 5.4.0 添加到 pom 属性中
            【解决方案20】:

            您缺少具有组的 JUnit 5 平台启动器:'org.junit.platform',名称:'junit-platform-launcher'

            只需添加你的 POM:

            <dependency>
                   <groupId>org.junit.platform</groupId>
                   <artifactId>junit-platform-launcher</artifactId>
                </dependency>
            

            【讨论】:

              【解决方案21】:

              由于无法将代码块发布到comments,这是我在需要 JUnit 5 的项目中使用的 POM 模板。这允许在 Eclipse 中构建和“作为 JUnit 测试运行”,并使用普通 Maven 构建项目。

              <project
                  xmlns="http://maven.apache.org/POM/4.0.0"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
                  <modelVersion>4.0.0</modelVersion>
              
                  <groupId>group</groupId>
                  <artifactId>project</artifactId>
                  <version>0.0.1-SNAPSHOT</version>
                  <name>project name</name>
              
                  <dependencyManagement>
                    <dependencies>
                      <dependency>
                      <groupId>org.junit</groupId>
                      <artifactId>junit-bom</artifactId>
                      <version>5.3.1</version>
                      <type>pom</type>
                      <scope>import</scope>
                      </dependency>
                    </dependencies>
                  </dependencyManagement>
              
                  <dependencies>
                    <dependency>
                      <groupId>org.junit.jupiter</groupId>
                      <artifactId>junit-jupiter-engine</artifactId>
                      <scope>test</scope>
                    </dependency>
              
                    <dependency>
                      <groupId>org.junit.platform</groupId>
                      <artifactId>junit-platform-launcher</artifactId>
                      <scope>test</scope>
                    </dependency>
              
                    <dependency>
                      <!-- only required when using parameterized tests -->
                      <groupId>org.junit.jupiter</groupId>
                      <artifactId>junit-jupiter-params</artifactId>
                      <scope>test</scope>
                    </dependency>
                  </dependencies>
              </project>
              

              您可以看到,如果您想更新 JUnit,现在只需在一处更新版本。此外,平台版本号不需要出现在 POM 中的任何位置(在兼容版本中),它是通过 junit-bom 导入自动管理的。

              【讨论】:

                【解决方案22】:

                您只能使用junit-jupiter 作为测试依赖项,而不是junit-jupiter-apijunit-platform-launcherjunit-jupiter-engine

                <dependency>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter</artifactId>
                    <version>5.5.2</version>
                    <scope>test</scope>
                </dependency>
                

                【讨论】:

                • 此解决方案适用于 JUnit 5.6.2、Java 11(和 eclipse 2020-03/4.15.0)
                【解决方案23】:

                我正在使用:

                弹簧工具套件 4 版本:4.4.2.RELEASE 内部版本号:201911201053 Java版本:1.8.0_191

                并且显示的消息是 没有找到测试运行器“JUnit5”的测试

                对我有用的是下面的配置

                    <properties>
                        <java.version>1.8</java.version>
                        <junit-jupiter.version>5.5.2</junit-jupiter.version>
                        <junit-platform.version>1.5.2</junit-platform.version>
                    </properties> 
                
                    <dependency>
                        <groupId>org.junit.jupiter</groupId>
                        <artifactId>junit-jupiter-engine</artifactId>
                        <version>${junit-jupiter.version}</version>
                        <scope>test</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.junit.platform</groupId>
                        <artifactId>junit-platform-launcher</artifactId>
                        <version>${junit-platform.version}</version>
                        <scope>test</scope>
                    </dependency>
                

                【讨论】:

                  【解决方案24】:

                  您应该确保您的测试用例函数是公开的而不是私有的,以便测试运行程序可以访问它。

                  @Test
                  private void testmethod(){}
                  

                  @Test
                  public void testmethod(){}
                  

                  【讨论】:

                    【解决方案25】:

                    @Test 注解必须从 org.junit.jupiter.api.Test 导入,这样 Junit5 才能读取它。 Junit4 使用从 org.junit.Test 包导入的@Test 注解。

                    【讨论】:

                      【解决方案26】:

                      我在 Eclipse 版本 Oxygen.3a Release (4.7.3a) 中遇到了同样的错误。 Maven 依赖项不匹配存在问题。为了解决,我已使用以下依赖项更新了我的 Pom.xml。

                      http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.netapp.junitnmactiopractice JunitAndMactioPractice 0.0.1-快照

                      <properties>
                          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                          <java.version>1.8</java.version>
                          <junit.jupiter.version>5.1.1</junit.jupiter.version>
                          <junit.platform.version>1.1.1</junit.platform.version>
                      </properties>
                      
                      <build>
                          <plugins>
                              <plugin>
                                  <artifactId>maven-compiler-plugin</artifactId>
                                  <version>3.1</version>
                                  <configuration>
                                      <source>${java.version}</source>
                                      <target>${java.version}</target>
                                  </configuration>
                              </plugin>
                          </plugins>
                      </build>
                      
                      <dependencies>
                          <dependency>
                              <groupId>org.junit.jupiter</groupId>
                              <artifactId>junit-jupiter-engine</artifactId>
                              <version>${junit.jupiter.version}</version>
                          </dependency>
                          <dependency>
                              <groupId>org.junit.platform</groupId>
                              <artifactId>junit-platform-runner</artifactId>
                              <version>${junit.platform.version}</version>
                              <scope>test</scope>
                          </dependency>
                      </dependencies>
                      

                      【讨论】:

                      【解决方案27】:

                      你应该改变

                      @Test
                      public static void testmethod(){}
                      

                      @Test
                      public void testmethod(){}
                      

                      @Test 不支持静态方法

                      【讨论】:

                        【解决方案28】:

                        对我来说,我配置了构建路径以添加 JUnit 5 库并添加依赖项

                             <dependency> 
                                <groupId>org.junit.platform</groupId> 
                                <artifactId>junit-platform-launcher</artifactId> 
                                <version>1.1.0</version> 
                                <scope>test</scope> 
                             </dependency>
                        

                        分开。

                        【讨论】:

                          【解决方案29】:

                          我也遇到了 Eclipse(版本:2019-12 (4.14.0))的这个问题。该解决方案似乎要么使用 IntelliJ,要么使用 Maven 测试在 Eclipse 中运行此类测试。

                          【讨论】:

                            【解决方案30】:

                            尝试将您的单元测试配置重新配置为项目 JRE。

                            【讨论】:

                              猜你喜欢
                              • 2018-03-24
                              • 2013-12-02
                              • 1970-01-01
                              • 2020-03-25
                              • 2020-04-11
                              • 2021-10-25
                              • 2018-10-11
                              • 2011-02-17
                              • 1970-01-01
                              相关资源
                              最近更新 更多