Eclipse没有使用由NoClassDefFoundError引起的JUnit 5的测试 [英] Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError

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

问题描述

问题



每当我运行我的项目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 (未知来源)
at java.base / java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.base / java.lang.Class.newInstance(Unknown Source)
在org.eclipse.jdt.internal.junit.runner.RemoteTes tRunner.createRawTestLoader(RemoteTestRunner.java:368)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createLoader(RemoteTestRunner.java:363)
at or.e.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)
引起: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(未知来源)
... 11更多



我尝试过的远



我已经尝试




  • 从构建中删除测试文件夹路径并重新添加。

  • 启动测试,将鼠标悬停在使用@Test注释的方法上,然后单击Run as JUnit Test。

  • 从Buildpath中删除JUnit并重新添加

  • 重启eclipse

  • 我也移动了项目从一台机器到另一台机器的整个项目,并使用提供的eclipse安装进行尝试

  • 重命名测试方法。

  • 重新输入@Test注释



其中一些步骤



另请参阅我在Eclipse Oxygen.1a中显示Java 9和JUnit 5的视频在行动


The problem

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.

The description

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:

Console output:

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

  • to remove the test folder from build path and add it again.
  • to start the test with hovering over the method annotated with @Test and then click "Run as JUnit Test".
  • remove JUnit from Buildpath and add it again
  • restart eclipse
  • I've also moved the project whole project from one machine to another machine and tried it with the provided eclipse installation there
  • to rename the test method.
  • to retype the @Test annotation

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

解决方案

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.

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:

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆