Eclipse没有找到由NoClassDefFoundError

Eclipse没有找到由NoClassDefFoundError

本文介绍了Eclipse没有找到由NoClassDefFoundError使用LauncherFactory引起的使用JUnit 5的测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我运行项目JUnit测试(将JUnit 5与Java 9和Eclipse Oxygen 1.a结合使用)时,都会遇到Eclipse无法找到任何测试的问题.

Whenever I run my projects JUnit test (using JUnit 5 with Java 9 and Eclipse Oxygen 1.a) I encounter the problem that eclipse can't find any tests.

在运行配置下,eclipse甚至找不到用@Test注释的方法,而是只显示"(所有方法)".下图希望可以更好地了解我的设置:

Under the run configuration, eclipse can't even find the method which is annotated with @Test, but instead only shows me "(all methods)".The following picture hopefully gives a better glimps of my setup:

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

到目前为止我尝试过的事情

我已经尝试过

What I tried so far

I've already tried

  • 要从构建路径中删除测试文件夹,然后再次添加.
  • 通过将鼠标悬停在@Test注释的方法上来开始测试,然后单击以JUnit Test身份运行".
  • 从Buildpath中删除JUnit并再次添加
  • 重启日食
  • 我还将整个项目从一台机器移到另一台机器上,并在那里使用提供的eclipse安装对其进行了尝试
  • 重命名测试方法.
  • 重新输入@Test批注

其中一些步骤可以在此处找到,但最后问题仍然存在.

Some of these steps can be found here, but in the end the problem remained.

推荐答案

您遇到了 Eclipse错误525948 ,该错误已修复,将在即将于2018年3月21日发布的Oxygen.3(4.7.3)版本中发布.

You ran into Eclipse bug 525948 which has already been fixed and which will be published in the upcoming release Oxygen.3 (4.7.3), March 21, 2018.

作为解决方法,将测试代码放入单独的项目,然后将被测试的项目添加到模块路径,但不要在测试项目中添加module-info.java.在您的项目,类和模块的命名中,它应该看起来像这样:

As workaround, put your test code in a separate project and add the project under test to the modulepath, but do not add a module-info.java to your test project. With your project, class and module naming, it should look something like this:

另请参见我的视频,该视频演示了运行中的Eclipse Oxygen.1a中的Java 9和JUnit 5. a>

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

这篇关于Eclipse没有找到由NoClassDefFoundError使用LauncherFactory引起的使用JUnit 5的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!