Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 545849

Summary: No Test found with test runner 'JUnit 5': NoSuchMethodError
Product: [Eclipse Project] JDT Reporter: Etienne Reichenbach <etienner>
Component: UIAssignee: Till Brychcy <register.eclipse>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: ajithinvincible, b.boeck, bernd.farka, christopher.lott, cvgaviao, etienner, gboccard, john.s.g.churchill, mail, mistria, noopur_gupta, pverheyden, pyvesdev, register.eclipse, sarika.sinha, sarma.swaranga, serge.simon, thatnitind, tk, woschtl85
Version: 4.11   
Target Milestone: 4.15 M1   
Hardware: PC   
OS: Windows 10   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=542742
https://git.eclipse.org/r/154944
https://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=3dd606caa9285a2d0bc7f458df1dff6c43cfc2d9
Whiteboard:
Attachments:
Description Flags
Small project to demo the problem none

Description Etienne Reichenbach CLA 2019-03-27 10:20:24 EDT
Created attachment 278036 [details]
Small project to demo the problem

Executing a JUnit 5 test on the latest eclipse version (Version: 2019-03 (4.11.0), Build id: 20190314-1200) I get an error dialog with No Test found with test runner 'JUnit 5' and the following exception in the logs:

java.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.execute(Lorg/junit/platform/launcher/TestPlan;[Lorg/junit/platform/launcher/TestExecutionListener;)V
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:89)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)

This only happens using version 1.1.0 of junit-platform-launcher, if I use 1.4.1 it works.
This used to work with eclipse 2018-12.

See attached project to reproduce the problem.
Comment 1 Swaranga Sarma CLA 2019-03-30 15:00:48 EDT
I am facing the same issue. On Ubuntu 16.04
Comment 2 Bernd Farka CLA 2019-04-04 10:24:12 EDT
I had a quick look into that problem

... if you want to use Junit 5.x with eclipse 2019-03 you have to use the latest Junit 5.4.. the support of older Junit 5.x versions (in my case 5.3) is broken...
Comment 3 John Churchill CLA 2019-04-04 13:52:32 EDT
I am already on 5.4.0, and the problem did not exist a few days ago while I was still on 5.4.0. Upgrading to 5.4.1 did not fix it either. Something else must be going on.
Comment 4 Etienne Reichenbach CLA 2019-04-05 04:40:53 EDT
In the example project I posted above, you can easily see that it is caused by the version junit-platform-launcher.

1.1.0 does not work
1.4.1 works.

In my opinion even if the problem gets fixed using another version of of the junit libraries, this is a bug of eclipse. It should not stop working depending on the libraries used in a project.
Comment 5 Bernd Farka CLA 2019-04-05 05:35:12 EDT
 Etienne Reichenbach: i fully agree, since it somehow a NoGo couple the version of a test-framework to your ide...
Comment 6 Noopur Gupta CLA 2019-04-08 10:10:09 EDT
*** Bug 545765 has been marked as a duplicate of this bug. ***
Comment 7 Samir Huremovic CLA 2019-04-23 05:09:11 EDT
Got the same problem.

Spent literally hours to find the cause... 

Is there a workaround other than changing the versions of the JUnit libraries?
Comment 8 Bernhard Böck CLA 2019-04-23 08:23:12 EDT
My workaround is adding the following library to the gradle build file:

testRuntime group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.4.1'
Comment 9 Samir Huremovic CLA 2019-04-23 09:59:18 EDT
(In reply to Bernhard Böck from comment #8)
> My workaround is adding the following library to the gradle build file:
> 
> testRuntime group: 'org.junit.platform', name: 'junit-platform-launcher',
> version: '1.4.1'

Thanks, but that does not help in my case, i get the exception below.

We also use junit-jupiter-engine and junit-jupiter-api in version 5.0.1. Changing the version of those two also did not fix the below problem.

As of now only thing that works is using Eclipse 2018-12. Sucks having to change the fully configured IDE just for this...

Since i am having this problem for the first time i am asking myself is Eclipse made to work with older JUnit5 versions too or to i need to update JUnit in my projects just because Eclipse is not working with it? 

Our projects are pretty large and most other devs use IntelliJ, so i can't justify changing the JUnit version just to make my Eclipse work again...


java.lang.NoClassDefFoundError: org/junit/platform/commons/logging/LoggerFactory
	at org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry.<clinit>(ServiceLoaderTestEngineRegistry.java:32)
	at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:87)
	at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:67)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.<init>(JUnit5TestLoader.java:34)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at java.base/java.lang.Class.newInstance(Class.java:584)
	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.logging.LoggerFactory
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 14 more
Comment 10 Samir Huremovic CLA 2019-04-23 10:00:34 EDT
Sorry, wrong versions for jupiter and api:

<junit.jupiter.version>5.0.0-M4</junit.jupiter.version>
<junit.platform.version>1.0.0-M4</junit.platform.version>
Comment 11 Samir Huremovic CLA 2019-04-23 10:02:41 EDT
LoL sorry that was not clear too...

junit.jupiter.version is used for both junit-jupiter-engine and junit-jupiter-api -> 5.0.0-M4.
Comment 12 Phillip Verheyden CLA 2019-04-23 12:04:43 EDT
Had the same problem and ensuring I was using JUnit 5.4 was the fix. I previously had JUnit 5.2 coming in via transitive dependencies in Groovy, even though I had specified Junit 5.4.1 as testCompile in my build.gradle.

To resolve, I had to add the following to build.gradle to remove the testing frameworks I didn't care about:

configurations {
    // No JUnit 4
    all*.exclude module: 'groovy-test'
    // No old version of JUnit 5
    all*.exclude module: 'groovy-test-junit5'
    // No TestNG
    all*.exclude module: 'groovy-testng'
}

And then add JUnit 5.4+ as a testCompile dependency:

dependencies {
  testCompile 'org.junit.jupiter:junit-jupiter:5.4.1'
}

Without excluding groovy-test-junit5, it looks like Junit 5.3 was selected as the one on the classpath that Eclipse recognized. With the above configuration I can successfully run JUnit 5 tests in Eclipse.
Comment 13 Swaranga Sarma CLA 2019-04-24 13:57:51 EDT
If Eclipse supports Junit5, it should support all the different versions of Junit5 and not tied to one major version which is disappointing.
Comment 14 John Churchill CLA 2019-04-27 19:07:59 EDT
I found the cause of my problem. In the Gradle subproject block at the top level, I had the testImplementation hard-coded to an older version of junit (5.3.1 and 1.3.1, I think), while the main build.gradle was using 5.4.1 / 1.4.1. I have hundreds of subprojects so this was kind of hard to detect. Updating everything to 5.4.2/1.4.2 (this time with a variable) solved it for me.
Comment 15 Ajith P CLA 2019-05-17 00:26:01 EDT
Is there any plan for Eclipse to fix it for Junit version 5.3? I have a dependency on 5.3 which I do not have the provision to upgrade to 5.4
Comment 16 Cristiano Gaviao CLA 2019-06-06 18:32:04 EDT
Have you guys tried to remove junit-platform-launcher from the project?

I have those in mine and it is working well:

<dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.junit</groupId>
			<artifactId>junit-bom</artifactId>
			<version>${junit.version}</version>
			<scope>import</scope>
			<type>pom</type>
		</dependency>
		<dependency>
			<groupId>org.mockito</groupId>
			<artifactId>mockito-junit-jupiter</artifactId>
			<version>${mockito.version}</version>
		</dependency>
		<dependency>
			<groupId>org.assertj</groupId>
			<artifactId>assertj-core</artifactId>
			<version>${assertj.version}</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-simple</artifactId>
			<version>${slf4j.version}</version>
		</dependency>
		<dependency>
			<groupId>info.solidsoft.mockito</groupId>
			<artifactId>mockito-java8</artifactId>
			<version>2.5.0</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
</dependencyManagement>
<dependencies>
	<dependency>
		<groupId>org.junit.jupiter</groupId>
		<artifactId>junit-jupiter-engine</artifactId>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>org.junit.jupiter</groupId>
		<artifactId>junit-jupiter-params</artifactId>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>org.junit.jupiter</groupId>
		<artifactId>junit-jupiter-api</artifactId>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>org.mockito</groupId>
		<artifactId>mockito-junit-jupiter</artifactId>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>org.assertj</groupId>
		<artifactId>assertj-core</artifactId>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-simple</artifactId>
		<scope>test</scope>
	</dependency>
</dependencies>
Comment 17 torsten piotraschke CLA 2019-06-07 07:43:56 EDT
The issue doesn't appear anymore in Eclipse version Version: 2019-06 M3 (4.12.0M3)
Build id: 20190530-0926, which I am using now.
Comment 18 Top Kat CLA 2019-06-10 15:13:59 EDT
Not sure if this is the same issue or just another symptom of a weak JUnit link.
After installing Eclipse 4.11 lately and upgrading to JDK 12 and JavaFX 12, I saw some red error markings on projects having JUnit tests. Simply going to the Java build path and manually adding the JUnit 5 library did not make the tests work.
The only way to get it going was:

1) Remove any JUnit library from the project.
2) Clean project and then go into the JUnit test file.
3) Hover over the first red error marking and select the link, "Fix Project Setup".
4) A window opens presenting the highlighted option, "Add JUnit 5 library to the build path". Click on the OK button. This adds JUnit 5.
5) Hover over any remaining error markings on the test file, e.g. errors due to missing import packages. Click on the relevant import options.

6) Before running the JUnit test, check that the Run Configuration is suitable for the test file and source file in question.
Comment 19 Samir Huremovic CLA 2019-06-14 08:55:32 EDT
(In reply to torsten piotraschke from comment #17)
> The issue doesn't appear anymore in Eclipse version Version: 2019-06 M3
> (4.12.0M3)
> Build id: 20190530-0926, which I am using now.

In our project we were using 5.0.0-M4 and 1.0.0-M4.

For these versions the new eclipse does not solve the problem. It is all the same as with the previous (2019-03) version.

I was lucky that i had the time to upgrade our code to the newest versions, because our codebase was not that extensive. So for me the issue was resolved by upgrading JUnit versions. I hope for the others that there still might be a fix for this.
Comment 20 Sebastian Thomas CLA 2019-07-12 03:53:16 EDT
I have the same issue running JUnit 5 tests in 2019-03 and 2019-06. Upgrading the project to Jupiter 5.5.0 did not help.

Everything is working perfectly in Eclipse 2018-12.
Comment 21 Chris Lott CLA 2019-08-08 09:21:32 EDT
Same problem in environment Mac OSX; openjdk 12.0.1 2019-04-16; Eclipse 19-06 (4.12.0).  I'm testing a Spring-Boot application, which sets the version of junit-platform-launcher to 1.3.1. I overrode the version to be 1.4.2 (see below) and then Eclipse can run JUnit tests. The very latest version 1.5.1 does NOT work. HTH

		<dependency>
			<groupId>org.junit.platform</groupId>
			<artifactId>junit-platform-launcher</artifactId>
			<!-- Override Spring-Boot choice for Eclipse -->
			<version>1.4.2</version>
			<scope>test</scope>
		</dependency>
Comment 22 Sebastian Thomas CLA 2019-08-08 10:28:13 EDT
I just noticed that the bug disappears for me if I use only "junit-jupiter" as a test dependency instead of "junit-jupiter-api", "junit-platform-launcher", "junit-jupiter-engine"... as individual dependencies. Using jupiter version 5.4.2.
Comment 23 Serge SIMON CLA 2019-11-09 18:41:59 EST
I still have this exact issue.
Reinstalled a new brand workspace today with : 
- eclipse 2019-09
- gradle 5.6
- junit 5.5.2 + platform 1.5.2
- my old project which was working fine

and whatever i do, i still have this blocking error : 

java.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.execute(Lorg/junit/platform/launcher/TestPlan;[Lorg/junit/platform/launcher/TestExecutionListener;)V
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:89)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)


I've tryed the various ideas suggested here without any luck (with or without platform, ...).

Right now my build.gradle contains : 

testImplementation "org.junit.jupiter:junit-jupiter-params:5.5.2"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
testRuntimeOnly 'org.junit.platform:junit-platform-commons:1.5.2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.5.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2'

(same problem with platform+launcher 1.4.2)
Comment 24 Mickael Istria CLA 2019-12-18 11:30:46 EST
It seems like JDT depends on outdated JUnit APIs, or there is some faulty classloading making the wrong version of JUnit used by the test runner.
I'm not sure it's a m2e bug, it seems a bit more like a JDT one. Adding some more expert JDT/JUnit developers to get their opinion.
Comment 25 Sarika Sinha CLA 2019-12-19 00:41:53 EST
(In reply to Serge SIMON from comment #23)
> I still have this exact issue.
> Reinstalled a new brand workspace today with : 
> - eclipse 2019-09
> - gradle 5.6
> - junit 5.5.2 + platform 1.5.2
> - my old project which was working fine
> 
> and whatever i do, i still have this blocking error : 
> 
> java.lang.NoSuchMethodError:
> org.junit.platform.launcher.Launcher.execute(Lorg/junit/platform/launcher/
> TestPlan;[Lorg/junit/platform/launcher/TestExecutionListener;)V
> 	at
> org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.
> run(JUnit5TestReference.java:89)
> 	at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:
> 41)
> 	at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.
> runTests(RemoteTestRunner.java:541)
> 	at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.
> runTests(RemoteTestRunner.java:763)
> 	at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.
> java:463)
> 	at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.
> java:209)
> 
> 
> I've tryed the various ideas suggested here without any luck (with or
> without platform, ...).
> 
> Right now my build.gradle contains : 
> 
> testImplementation "org.junit.jupiter:junit-jupiter-params:5.5.2"
> testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
> testRuntimeOnly 'org.junit.platform:junit-platform-commons:1.5.2'
> testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.5.2'
> testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
> 
> (same problem with platform+launcher 1.4.2)

Can you try using Junit 5.5.1 jar shipped with Eclipse Platform to see if it works?
Created Bug 558449 to support 5.5.2.

Some combination is not expected to work as previously junit jars did not have module details.
Comment 26 Till Brychcy CLA 2019-12-21 09:33:16 EST
This is caused by the changes for bug 542742, which is an optimization that uses a different overload of the "execute" method that was only introduced in junit-platform-launcher 1.4 (JUnit 5.4).

This can easily be fixed by using the old overload if the method is not present.
Comment 27 Till Brychcy CLA 2019-12-21 09:35:23 EST
Moving to JDT
Comment 28 Eclipse Genie CLA 2019-12-21 09:45:40 EST
New Gerrit change created: https://git.eclipse.org/r/154944
Comment 30 Till Brychcy CLA 2019-12-21 11:44:07 EST
(In reply to Eclipse Genie from comment #29)
> Gerrit change https://git.eclipse.org/r/154944 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/
> ?id=3dd606caa9285a2d0bc7f458df1dff6c43cfc2d9

Released for 4.15M1