I've just upgraded to Eclipse 2018.09 (the problem also occurs on Eclipse Photon), but it doesn't play nicely with a project that uses JUnit 4. The new version appears to run all tests using a JUnit 5 runner by default, which fails with the following errors because I only have JUnit 4 on the project's classpath, not JUnit 5:
java.lang.NoClassDefFoundError: org/junit/platform/engine/EngineExecutionListener at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:59) 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.engine.EngineExecutionListener at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 12 more
I want to be able to conveniently run my tests in this project without upgrading to a new major version of JUnit with a workaround I don't have to constantly repeat. I'm thinking that this will require somehow changing the default test runner.
Workarounds I've discovered, and why I'm not satisfied by them:
Eclipse Photon version info:
Eclipse Java EE IDE for Web Developers. Version: Photon Release (4.8.0) Build id: 20180619-1200 OS: Windows 7, v.6.1, x86_64 / win32 Java version: 1.8.0_171
"Check for Updates" shows no relevant packages to install.
Eclipse 2018.09 version info:
Eclipse Java EE IDE for Web Developers. Version: 2018-09 (4.9.0) Build id: 20180917-1800 OS: Windows 7, v.6.1, x86_64 / win32 Java version: 1.8.0_171
If a test class doesn't have this annotation, JUnit 4 runs it by using the default test runner that is called the BlockJUnit4ClassRunner . A test class can use only test runner.
I also stumbled upon this issue today. It seems that eclipse uses the JUnit 5 runner by default if JUnit 5 dependencies are found on the classpath.
In case of my maven project, investigating the dependency hierarchy showed that actually both JUnit 4 and JUnit 5 dependencies were on the classpath. JUnit 4 as the test dependency I added myself, JUnit 5 as a transitive dependency which I inherited from another library I relied upon. After excluding JUnit 5 from that dependency, eclipse again uses the JUnit 4 runner by default.
Maybe you could check if your project also has an unwanted dependency to JUnit 5 you are not aware of?
In my case the project was created with Spring Initializr and it had automatically added the following exclusion to the spring-boot-starter-test dependency:
<exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion>
Removing it fixed the problem for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With