Eclipse中Maven项目JUnit 5测试隔次执行失败求助
JUnit 5 Launch Configuration Fails Alternately in Eclipse Maven Project ("No tests found with test runner JUnit 5")
I'm hitting a weird intermittent issue with JUnit 5 launch configurations in Eclipse on a Maven project that includes both source and test code. Here's what's happening:
- The launch configuration seems correctly set up.
- First execution after building the project works perfectly fine.
- Second run of the same configuration throws the error
No tests found with test runner JUnit 5, accompanied by the stack trace below. - Third execution works again, and this success/failure cycle repeats indefinitely.
java.lang.NoClassDefFoundError: org/junit/platform/commons/util/Preconditions at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:83) at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:67) at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.<init>(JUnit5TestLoader.java:34) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at java.lang.Class.newInstance(Class.java:442) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createRawTestLoader(RemoteTestRunner.java:370) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createLoader(RemoteTestRunner.java:365) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:309) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.init(RemoteTestRunner.java:224) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:208) Caused by: java.lang.ClassNotFoundException: org.junit.platform.commons.util.Preconditions at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 13 more
I've done some initial troubleshooting:
- The stack trace is just a symptom — the
org.junit.platform.commons.util.Preconditionsclass exists in my local Maven repository, andjunit-platform-commonsis a transitive dependency in the project. - The key difference I found is in the
URLClassLoaderclasspath between successful and failed runs:- Success case: The second classloader includes both the project JAR and all dependency JARs from my local
.m2repository. - Failure case: The second classloader only includes the project JAR and Eclipse OSGi-related paths, not the Maven dependencies.
- Success case: The second classloader includes both the project JAR and all dependency JARs from my local
- The launch configuration's classpath settings should directly control the
URLClassLoaderpath, but they seem to fail every other execution.
Has anyone encountered this alternating success/failure issue with JUnit 5 launch configurations in Eclipse before? Or can anyone suggest a solution or further troubleshooting steps?
Environment: Eclipse IDE for Java Developers Version: 2019-09 R (4.13.0) Build id: 20190917-1200, all plugins are up to date.
内容的提问来源于stack exchange,提问作者Frank
相关产品推荐
相关产品推荐

