This code will display the NoSuchMethodError: "java.util.Set org.junit.platform.engine.TestDescriptor.getAncestors()". Here are some possible solutions to this error:
Solution 1: Update Gradle Dependencies
Add the following dependency to the build.gradle file:
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
Alternatively, you can use STS 4.20.0 distro based on Eclipse 4.28 or refer to the GitHub issue below for more workarounds and an explanation of the problem:
https://github.com/eclipse/buildship/issues/1265Solution 2: Add Missing Dependency
In some cases, the error can be caused by a missing dependency in the pom.xml file. Ensure that the following dependency is present:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
Solution 3: Update junit-platform-launcher Dependency
For STS 4.21.0.RELEASE, update the junit-platform-launcher dependency to version 1.8.2 in the pom.xml file:
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.8.2</version>
<scope>test</scope>
</dependency>
Solution 4: Migrate to JUnit 5.10.2
For Eclipse for Java users, migrating from JUnit 5.9.2 to 5.10.2 in the pom.xml file may resolve the issue.