Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eclipse IDE - JUnit5 test runner is picked instead of JUnit4 #4284

Closed
blacelle opened this issue Jan 28, 2025 · 6 comments
Closed

Eclipse IDE - JUnit5 test runner is picked instead of JUnit4 #4284

blacelle opened this issue Jan 28, 2025 · 6 comments

Comments

@blacelle
Copy link

I open a maven multi-module project in Eclipse 2024-12 (though it happens since multiple previous Eclipse versions).

My maven projects brings dependencies:

  • org.junit.vintage:junit-vintage-engine:5.10.3
  • org.junit.plateform:junit-plateform-engine:1.10.3
  • org.junit.plateform:junit-plateform-commons:1.10.3
  • junit:junit:4.13.2

And nothing matching jupiter.

But Eclipse Test Runner is automatically configured on JUnit5, which fails with stacks like:

org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests
	at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:160)
	at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverSafely(EngineDiscoveryOrchestrator.java:132)
	at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:107)
	at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:78)
	at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:99)
	at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:77)
	at org.junit.platform.launcher.core.DelegatingLauncher.discover(DelegatingLauncher.java:42)
	at org.junit.platform.launcher.core.SessionPerRequestLauncher.discover(SessionPerRequestLauncher.java:56)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.<init>(JUnit5TestReference.java:47)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createUnfilteredTest(JUnit5TestLoader.java:88)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createTest(JUnit5TestLoader.java:69)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.loadTests(JUnit5TestLoader.java:56)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:514)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:758)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:453)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:211)
Caused by: org.junit.platform.commons.JUnitException: ClassSelector [className = 'io.mitrust.sharing.TestClaimsDeprecationHelper', classLoader = jdk.internal.loader.ClassLoaders$AppClassLoader@1e2e2406] resolution failed
	at org.junit.platform.launcher.listeners.discovery.AbortOnFailureLauncherDiscoveryListener.selectorProcessed(AbortOnFailureLauncherDiscoveryListener.java:39)
	at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequestResolution.java:103)
	at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.run(EngineDiscoveryRequestResolution.java:83)
	at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolver.resolve(EngineDiscoveryRequestResolver.java:113)
	at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.resolveSelectors(DiscoverySelectorResolver.java:48)
	at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:69)
	at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:152)
	... 15 more
Caused by: java.lang.NoSuchMethodError: 'boolean org.junit.platform.commons.util.ReflectionUtils.returnsPrimitiveVoid(java.lang.reflect.Method)'
	at org.junit.jupiter.engine.discovery.predicates.IsTestableMethod.test(IsTestableMethod.java:48)
	at org.junit.jupiter.engine.discovery.predicates.IsTestMethod.test(IsTestMethod.java:23)
	at org.junit.jupiter.engine.discovery.predicates.IsTestableMethod.test(IsTestableMethod.java:26)
	at java.base/java.util.function.Predicate.lambda$or$2(Predicate.java:101)
	at java.base/java.util.function.Predicate.lambda$or$2(Predicate.java:101)
	at org.junit.platform.commons.util.ReflectionUtils.findMethod(ReflectionUtils.java:1410)
	at org.junit.platform.commons.util.ReflectionUtils.isMethodPresent(ReflectionUtils.java:1306)
	at org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests.hasTestOrTestFactoryOrTestTemplateMethods(IsTestClassWithTests.java:50)
	at org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests.test(IsTestClassWithTests.java:46)
	at org.junit.jupiter.engine.discovery.ClassSelectorResolver.resolve(ClassSelectorResolver.java:67)
	at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.lambda$resolve$2(EngineDiscoveryRequestResolution.java:135)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1685)
	at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
	at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647)
	at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:189)
	at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:126)
	at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequestResolution.java:92)
	... 20 more

Steps to reproduce

This happens on a complex private multi-module project. I could try making a simpler repository if necessary.

Context

  • Used versions (Jupiter/Vintage/Platform): 1.10.3
  • Build Tool/IDE: Eclipse 2024-12

https://bugs.eclipse.org/bugs/show_bug.cgi?id=578100


Should I look for a specific dependency to understand why JUnit5 kicks-in?

@sormuras
Copy link
Member

sormuras commented Jan 28, 2025

Please use the JUnit BOM in your Maven POM to align all versions of JUnit artifacts. It seems like Eclipse is providing the wrong version of Jupiter engine when running tests.

Find more details here: https://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven-bom

See also:

PS: And if Eclipse (and others) would run JUnit on the module path, we would be able to spot the version mismatch right in the stacktrace.

@blacelle
Copy link
Author

Please use the JUnit BOM in your Maven POM to align all versions of JUnit artifacts. It seems like Eclipse is providing the wrong version of Jupiter engine when running tests.

The project essentially do:

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.7.18</version>
		<!-- http://stackoverflow.com/questions/6003831/parent-relativepath-points-at-my-com-mycompanymyproject-instead-of-org-apache -->
		<relativePath />
	</parent>

	<properties>
		<!-- JUnit4 latest is 4.13.2 -->
		<!-- Still, we can upgrade the BOM for latest utilities-->
		<junit-jupiter.version>5.10.3</junit-jupiter.version>
	</properties>


				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-surefire-plugin</artifactId>
					<version>3.5.2</version>
					<configuration>
						<argLine><![CDATA[-Xmx256M -XX:+StartAttachListener -Djava.util.logging.config.file=logging.properties -Djdk.attach.allowAttachSelf=true ${surefire.additionalArgument} ${argLine}]]></argLine>
					</configuration>
				</plugin>

which looks acceptable regarding the user-guide.

I upgraded to:

<junit-jupiter.version>5.11.4</junit-jupiter.version>

and this issue is fixed!

TY


PS: And if Eclipse (and others) would run JUnit on the module path, we would be able to spot the version mismatch right in the stacktrace.

Do you mean Eclipse does something wrong, or my pom.xml does something wrong?

@sormuras
Copy link
Member

...
and this issue is fixed!

In the light of this, I'm closing this issue.

Ah, Spring Boot is in the mix, too. What you now have looks similar to what the docs state: https://junit.org/junit5/docs/current/user-guide/#running-tests-build-spring-boot

Do you mean Eclipse does something wrong, or my pom.xml does something wrong?

As long as mvn works as expected on the command line, your pom.xml should be fine. Using the same Maven project declaration imported into Eclipse and it see it fail? Then something's off in Eclipse.

What I was refering to is that you get version information for granted, from explicit modules mounted on the module path. For example:

Failures (1):
  JUnit Jupiter:JUnitTests:test()
    MethodSource [className = 'test.junit.JUnitTests', methodName = 'test', methodParameterTypes = '']
    => org.opentest4j.AssertionFailedError
       [email protected]/org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:34)
       [email protected]/org.junit.jupiter.api.Assertions.fail(Assertions.java:119)
       test.junit@2024-ea/test.junit.JUnitTests.test(JUnitTests.java:9)

Copy link

Please assign a milestone to this issue or label it with type: task or type: question.

@sormuras
Copy link
Member

Please assign a milestone to this issue or label it with type: task or type: question.

@marcphilipp Let's include status: invalid in the set of label not requiring a milestone.

@marcphilipp marcphilipp closed this as not planned Won't fix, can't repro, duplicate, stale Jan 28, 2025
@marcphilipp
Copy link
Member

Let's include status: invalid in the set of label not requiring a milestone.

@sormuras You don't need a milestone if you close it as "not planned".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants