How can I get Eclipse 2018.09 to use the JUnit 4 test runner by default?

run as junit not showing in eclipse
eclipse default to junit 4
eclipse not recognizing junit test
no tests found with runner 'junit 5
how to run junit in eclipse
the type org junit-jupiter-api assertions is not accessible
junit 5 test suite eclipse
cannot find class org/junit-platform commons annotation testable on project build path

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:

  1. Manually update every run configuration for every test to use the JUnit 4 runner. I'm not satisfied with this because it's annoying and a lot of work. I cannot find a way to change the JUnit run configuration defaults to always use the JUnit 4 runner. There's some promising-seeming stuff about "prototype" run configurations, but all the options are greyed-out and nonfunctional for JUnit configurations.
  2. Add JUnit 5 to the classpath. This allows the JUnit 5 runner to work, but I'm not satisfied with this because I shouldn't be forced to upgrade on account of my IDE.

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

In my case the project was created with Spring Initializr and it 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.

java, I faced the same issue now, and got it fixed after adding the Vintage Engine dependency in the POM.xml file. Try it out. MVN Repository:  When Eclipse is opened, a quick check to see if JUnit was included is to go to: File -> New -> JUnit Test Case. If this option is there, JUnit was included. If not, you can instead select: Help -> Install New Software. within Eclipse. In the Work with: field, your Eclipse version should have a Site entry in the dropdown, such as:

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?

Embracing JUnit 5 with Eclipse, JUnit 5 is out the door as the next generation test framework. JUnit 4 was a big ball of mud with a single junit.jar to be used by test developers, testing These default test methods can be inherited by implementing test classes, thereby In Eclipse, you can use the Go to File action or double-click on a test method in JUnit  A simple solution is to make the individual test classes abstract (public/non-public doesn't matter) so that JUnit won't execute them, and inside the test suite we simply use concrete subclasses of the original abstract test classes: import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners

I faced the same issue now, and got it fixed after adding the Vintage Engine dependency in the POM.xml file. Try it out.

MVN Repository: https://mvnrepository.com/artifact/org.junit.vintage/junit-vintage-engine

Set up JUnit in Eclipse, JUnit simplifies the Unit testing process in Java with visual indicators and a Unit testing framework. JUnit use in the Eclipse IDE is convenient and quick to  I'm a newbie to JUnit. I have created some tests inside of eclipse and using "Run as" inside of eclipse to execute my tests. I want to know how can I run these same tests from a command line? Example, what are all the steps necessary? I have set my environment variables (e.g. JAVA_HOME and JUNIT_HOME) and also added them to the classpath as well.

Configure Eclipse to use JUnit, The functionality of junit4 is essentially an extension of junit3.8.1, but with Eclipse discourages using default packages, but will permit the package to be left blank TestRunner.run( BlobTest.class ); } Graphical User Interface output: public  Write less, test more! The main feature of JUnit-Tools is to generate JUnit test-elements (packages, classes, methods, test-cases, mocks) depending on an existing java-class and logic. It supports the Test-After Development: Create JUnit-tests after writing or modifying application code.

Unit Testing with JUnit - Tutorial, By default, this view shows all tests. You can also configure, Eclipse creates run configurations for tests. You can see and  A JUnit Runner is class that extends JUnit's abstract Runner class. Runners are used for running test classes. The Runner that should be used to run a test can be set using the @RunWith annotation. @RunWith(MyTestRunner.class) public class MyTestClass { @Test public void myTest() { .. } } JUnit tests are started using the JUnitCore class.

JUnit 4 Tutorial: Eclipse Luna plugin - 2020, Notice the static import of this class at the top of Concatenation . Running test case. Once we have written our test methods, we want to run our JUnit test case:. Use png with transparent icon in the about dialog of Java EPP (and others if applicable) NEW: 530698: Using weka api: NEW: 526611: win64 version missing: NEW: 498457: FileNotFoundException : org.eclipse.ui_3.108.0.v20160518-1929.jar: NEW: 489296: Improve out-of-box experience for non-english locales: NEW: 386806: New Eclipse Icon not used by

Comments
  • Before you comment, remember I don't want to solve this issue by upgrading to JUnit 5.
  • Before you ask an Eclipse question, make sure your Eclipse IDE is up to date. ;-) Please upgrade to Eclipse 2018-09 (4.9).
  • The same problem occurs on a new install of Eclipse 2018-09 (4.9).
  • Having same problem. Not sure classpath is going to help. I am having mvn driven project. As such its not about support, its about setting default junit version at the IDE or workspace level.
  • I had the same problem with mvn project that was caused by junit-jupiter-api which pulled in junit5. after removing <dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-api</artifactId></dependency> all was fine for me.
  • I've always found the way Eclipse shows dependencies quite clunky (not even alphabetically sorted!). Do you have any advice on how to investigate the dependency hierarchy?
  • Thanks, but I consider that a workaround. I do not think I should have to modify the classpath of my project on account of the IDE. Especially since the IDE is perfectly happy to run tests with the JUnit 4 runner (it just makes it annoying and impractical).