NoSuchMethodError: 'java.util.Set org.junit.platform.engine.TestDescriptor.getAncestors()
Asked Answered
A

7

14

I get this error while running a JUnit test in Spring Tool Suite (4.20.0).

Test runs fine, but this error is thrown at the end -

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)

This is my Gradle plugins section -

plugins {
    id 'java'
    id 'eclipse'
    id 'eclipse-wtp'
    id 'org.springframework.boot' version "3.1.4"
    id 'io.spring.dependency-management' version "1.1.3"
}

This is my Gradle dependencies section -

implementation("org.springframework.boot:spring-boot-starter-parent:3.1.4")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-configuration-processor")
implementation("org.springframework.boot:spring-boot-starter-test")

What am I doing wrong?

My test class is very basic -

@ExtendWith(SpringExtension.class)
@ContextConfiguration(initializers = ConfigDataApplicationContextInitializer.class, classes = { TransformService.class})
@Slf4j
public class TransformServiceTest {

    @Autowired
    TransformService transformService;

    @Test
    public void transformXmlTest() throws Exception {
        transformService.transformXml();
    }
}

So, is my service class -

@Service
@Slf4j
public class TransformService {

    public void transformXml() {
        log.info("Transforming XML");
    }
}

I am running the test in STS by right-clicking on "TransformXmlTest()" in the Package Explorer and clicking "Run as - JUnit Test". (When I run it outside STS using Gradle task, everything looks clean).

This is the full log entry -

OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
2023-10-06 10:00:33.097  INFO Transforming XML | com.dowill.xsl.service.TransformService
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)

Thank you for the help

Admetus answered 6/10, 2023 at 3:58 Comment(4)
Please take the tour to learn how Stack Overflow works and read How to Ask or how to improve the quality of your question. Then edit your question to include your full source code you have as a minimal reproducible example, which can be compiled and tested by others. Included sources should be in text format, not an image.Ed
Sorry, thought my initial post would be enough to provide a lead. Added more code now. Let me know if I missed anything.Admetus
I assume there are mixed / conflicted versions of different JUnit Jupiter modules. The relevant method was released in JUnit 5.10 (Jul 23, 2023). Ensure all that JUnit related dependencies, even the plugin modules (platform, engine, launcher, etc.) are using the same compatible versions.Ed
I checked the dependency tree and I only have 5.9.3 of junit-jupiter and 1.9.3 of junit-platform. Dependency is managed by spring dependency manager. This error only hsows when I run the test in STS. When I run it outside (using gradle task), everything looks fine. So, I am assuming it is something to do with how STS/Eclipse is configured . I tried updating all software, but to no avail.Admetus
A
3

I switched to STS 4.19.0 and not seeing this error anymore. Wonder if this is an issue with STS 4.20.0.

I have tagged spring-tools-4 here hoping that someone from the STS community will take a look.

Admetus answered 8/10, 2023 at 16:24 Comment(4)
That looks strange. I checked STS 4.20 plugins and it contains latest versions of JUnit 5 engines/platforms. My suspicion is that STS still contains old versions in JUnit Core that is not compatible with new versions.Lamere
It has to do something with buildship i suppose (Gradle integration into Eclipse). If I try exactly the same project with Maven the tests run fine.Kisung
Same happened me too, switching back to old version resolved the issuePostmistress
I experienced it with STS 4.21.0.RELEASE, too.Nysa
K
17

This has to with Gradle and its integration into Eclipse (Buildship). You'd get the same behaviour in plain Eclipse for Java Developers.

The solution is add the below to the dependencies in build.gradle:

testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

You could also use STS 4.20.0 distro based on Eclipse 4.28 rather than latest 4.29 or look for more workaround in the issue below - very helpful. There is also the explanation what went wrong with eclipse 4.29 distro.

More info can be found here: https://github.com/eclipse/buildship/issues/1265

Kisung answered 11/10, 2023 at 15:1 Comment(1)
Thank you very much for that link. Wonder why that didn't come up when I searched around with my error message. Anyway, I will just stick with STS 4.19.0 for now.Admetus
A
3

I switched to STS 4.19.0 and not seeing this error anymore. Wonder if this is an issue with STS 4.20.0.

I have tagged spring-tools-4 here hoping that someone from the STS community will take a look.

Admetus answered 8/10, 2023 at 16:24 Comment(4)
That looks strange. I checked STS 4.20 plugins and it contains latest versions of JUnit 5 engines/platforms. My suspicion is that STS still contains old versions in JUnit Core that is not compatible with new versions.Lamere
It has to do something with buildship i suppose (Gradle integration into Eclipse). If I try exactly the same project with Maven the tests run fine.Kisung
Same happened me too, switching back to old version resolved the issuePostmistress
I experienced it with STS 4.21.0.RELEASE, too.Nysa
D
2

in sts 4.22 eclipse base update this is work to.

<dependency>
     <groupId>org.junit.platform</groupId>
     <artifactId>junit-platform-launcher</artifactId>
     <version>1.8.2</version>
     <scope>test</scope>
</dependency>
Dun answered 30/5 at 19:17 Comment(0)
B
1

For following STS:

Spring Tool Suite 4 
Version: 4.21.0.RELEASE
Build Id: 202312011804
Revision: 37b067849b907f022f6dabc8a04af38bbf291249

Below solution got worked:

Update the junit-platform-launcher dependency to 1.8.2 i.e

<dependency>
     <groupId>org.junit.platform</groupId>
     <artifactId>junit-platform-launcher</artifactId>
     <version>1.8.2</version>
     <scope>test</scope>
</dependency>
Botchy answered 5/1 at 7:4 Comment(1)
Yaaay it worked! I didn't have this dependency at all.Meingoldas
Q
0

In my case, I was missing the dependency 'org.junit.jupiter:junit-jupiter' - I only had 'org.junit.jupiter:junit-jupiter-api' in my pom.

Missing the jupiter base dependency caused these errors:

  • In IntelliJ, when I tried to run the tests explicitly: "no tests were found"
  • from command line, running mvn clean install: "there was an error in the forked process 'java.util.set org.junit.platform.engine.testdescriptor.getancestors()'"

🤦

Qadi answered 11/12, 2023 at 19:29 Comment(1)
Thanks, this can be the reason too, I have downvoted by mistake. For me the final solution was to re-import the project (delete intellij files)Nurserymaid
R
0

I had the same problem on Eclipse for Java. I solved it by migrating on pom from junit 5.9.2 to 5.10.2

Rondelle answered 13/2 at 8:28 Comment(0)
N
0

For me running from the command line the solution was to remove the

    <dependency>
        <groupId>org.junit.vintage</groupId>
        <artifactId>junit-vintage-engine</artifactId>
        <version>5.9.2</version>
    </dependency>

Using only the junit-jupiter-api works

    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>          
        <version>5.10.3</version>
        <scope>test</scope>
    </dependency>

** update: closing IntelliJ , delete the intellij files from the directory of the maven project and importing the project again helps too. Maybe you have the proper dependencies, but IntelliJ Maven "plugin" gets stuck .

Nurserymaid answered 15/8 at 7:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.