Skip to content

NoSuchMethodError when running a JUnit 5.9.3 test in Eclipse 2023-09 (4.29) #1265

Open
@howlger

Description

@howlger

Running a JUnit 5.9.3 test (e.g. via right-click and choosing Run As > JUnit Test) fails in Eclipse 2023-09 (4.29) with NoSuchMethodError.

build.gradle to reproduce this issue:

apply plugin: 'java'
java {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}
repositories {
    mavenCentral()
}
dependencies {    
    testImplementation 'org.junit.jupiter:junit-jupiter:5.9.3'
}

JUnit 5 test to reproduce this issue:

class Sample {
	@org.junit.jupiter.api.Test
	void test() {
		org.junit.jupiter.api.Assertions.assertTrue(true);
	}
}

Following stack trace will be printed to the Console view:

java.lang.NoSuchMethodError: 'java.util.Set org.junit.platform.engine.TestDescriptor.getAncestors()'
	at org.junit.platform.launcher.core.StackTracePruningEngineExecutionListener.getTestClassNames(StackTracePruningEngineExecutionListener.java:50)
	at org.junit.platform.launcher.core.StackTracePruningEngineExecutionListener.executionFinished(StackTracePruningEngineExecutionListener.java:39)
	at org.junit.platform.launcher.core.DelegatingEngineExecutionListener.executionFinished(DelegatingEngineExecutionListener.java:46)
	at org.junit.platform.launcher.core.OutcomeDelayingEngineExecutionListener.reportEngineFailure(OutcomeDelayingEngineExecutionListener.java:83)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:203)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:169)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:93)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:58)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:141)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:57)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:103)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:94)
	at org.junit.platform.launcher.core.DelegatingLauncher.execute(DelegatingLauncher.java:52)
	at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:70)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:98)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)

Workarounds:

  • In build.gradle, add the dependency testImplementation 'org.junit.platform:junit-platform-launcher:1.9.3' or
  • Upgrade to JUnit 5.10.0: testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0' or
  • For Spring Boot projects, in the preferences Gradle (for all projects) or in Project > Properties: Gradle (for a specific project) in the section Program Arguments click the Add button and add the program argument -Pjunit-jupiter.version=5.10.0 (see @danielerepici's Stack Overflow answer)

Cause:
It seems Buildship does not choose the corresponding junit-platform-launcher (as m2e seems to do; at least this issue cannot be reproduced with Maven), but uses the junit-platform-launcher version that is shipped with Eclipse. And in Eclipse 4.29 junit-platform-launcher has been upgraded to 1.10.0. But org.junit.platform:junit-platform-launcher:1.10.0 calls org.junit.platform.engine.TestDescriptor.html::getAncestors which has been introduced in org.junit.platform:junit-platform-engine:1.10.0 and which is missing in org.junit.platform:junit-platform-engine:1.9.3 in JUnit 5.9.3.

See also the following Stack Overflow questions:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions