升级 Eclipse 后 JUnit 测试上的 NoSuchMethod(使用 Gradle)

问题描述 投票:0回答:1

我使用的是 Eclipse 2022-09,一切正常。

我通过 Gradle 管理所有依赖项。 JUnit 5 的版本由 Spring Boot 管理插件定义。

升级到 Eclipse 2023-09 后,从 Eclipse 中执行 JUnit 测试时开始失败。

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)

JVM 是 Adoptium OpenJDK 17(17.0.8.101-热点)。

通过

gradlew test --tests Xyz
执行测试就可以了。问题是当我在 Eclipse 中运行测试(任何测试)时。

我已经搜索了几个小时,但找不到合适的解决方案或有意义的解释。

java spring-boot eclipse gradle junit5
1个回答
0
投票

这似乎是 Eclipse Buildship 的问题,JUnit 低于 5.10.0 和 Eclipse 2023-09 (4.29),我在这里报告:

Eclipse Buildship 问题 #1265:在 Eclipse 2023-09 (4.29) 中运行 JUnit 5.9.3 测试时出现 NoSuchMethodError

解决方法

  • build.gradle
    中,添加依赖项
    testImplementation 'org.junit.platform:junit-platform-launcher:1.9.3'
  • 升级到 JUnit 5.10.0:
    testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'

原因

Buildship 似乎没有选择相应的

junit-platform-launcher
(m2e 似乎也是这样做的;至少这个问题无法用 Maven 重现),而是使用 Eclipse 附带的
junit-platform-launcher
版本。并且在Eclipse 4.29中
junit-platform-launcher
已经升级到1.10.0。但是
org.junit.platform:junit-platform-launcher:1.10.0
调用了
org.junit.platform.engine.TestDescriptor.html::getAncestors
,它已在
org.junit.platform:junit-platform-engine:1.10.0
中引入,但在 JUnit 5.9.3 的
org.junit.platform:junit-platform-engine:1.9.3
中缺失。

© www.soinside.com 2019 - 2024. All rights reserved.