The Problem:
An error occurred while attempting to run tests using Junit 5 in a maven project, causing tests to fail to be detected. The error message "TestEngine with ID ‘junit-jupiter’ failed to discover tests" was displayed, along with a Java class definition error and a class not found exception.
The project uses Intellij Community Edition and includes the necessary dependencies for Junit 5. However, despite trying various versions of Junit-jupiter-engine and Maven-surefire-plugin, the error persists. The pom.xml configuration appears to be correct, but the tests are still not being discovered by the test engine.
The Solutions:
Solution 1: Resolve version conflict between ‘junit-jupiter-engine’ and ‘kotlin-test-junit5’
Issue:
In your pom.xml, you have two dependencies:
– `kotlin-test-junit5:1.7.10` (transitively depends on `junit-jupiter-api:5.6.0`)
– `junit-jupiter-engine:5.8.2` (requires `junit-jupiter-api:5.8.2`)
Solution:
This version conflict occurs because ‘junit-jupiter-engine’ and ‘kotlin-test-junit5’ both depend on ‘junit-jupiter-api’, but with different versions (5.8.2 and 5.6.0, respectively). To resolve the conflict, remove the `junit-jupiter-engine` dependency from your pom.xml since it’s already brought in by `kotlin-test-junit5` (verify using `mvn dependency:tree -Dverbose`). This will ensure that all dependencies use the same version of `junit-jupiter-api`.
Solution 2: Check for *.feature file with unsupported content
In some cases, the error TestEngine with ID 'junit-jupiter' failed to discover tests
can occur due to the presence of a *.feature file with unsupported content. Ensure that all *.feature files adhere to the Gherkin syntax and do not contain any unrecognized characters or syntax. Such unsupported content can interfere with the test discovery process and cause the error.
To resolve this issue, review all *.feature files and ensure that they are properly formatted according to the Gherkin syntax. Remove any unsupported content or characters that may be causing the issue. Once the *.feature files are corrected, try running the tests again to see if the error persists.
Q&A
Why is the error failed to discover tests
thrown while running Junit 5 tests in a maven project?
It could be due to dependency conflict between transitive dependencies.
How to resolve the dependency conflict?
Remove junit-jupiter-engine
from the pom.xml
as it is already transitively brought in by kotlin-test-junit5
.
What if the error message contains failed to discover tests
but from other test engine?
Check the surefire dump for a hint on which feature file the parsing went wrong.
Video Explanation:
The following video, titled "Helldivers 2 How to Fix Failed to Join Game Lobby Error ...", provides additional insights and in-depth exploration related to the topics discussed in this post.
4 days ago ... ... receiving the Helldivers 2 failed to join game lobby error pop up so in this video we're going through how to fix ...
The following video, titled "Helldivers 2 How to Fix Failed to Join Game Lobby Error ...", provides additional insights and in-depth exploration related to the topics discussed in this post.
4 days ago ... ... receiving the Helldivers 2 failed to join game lobby error pop up so in this video we're going through how to fix ...