3

While running the Junit 5 test cases facing the below issue.

CMD: $ mvn test -Dtest=com.app.AppTest -DskipTests=false (run only a specific test file, based on need and Jdk 1.8.0_232 with apache-maven-3.8.6 )

Error:

[INFO] --- maven-surefire-plugin:3.0.0-M7:test (default-test) @ projects-test ---
[WARNING] Error injecting: org.apache.maven.plugin.surefire.SurefirePlugin
java.lang.NoClassDefFoundError: org/apache/maven/surefire/api/testset/TestSetFailedException
    at java.lang.Class.getDeclaredConstructors0 (Native Method)
    at java.lang.Class.privateGetDeclaredConstructors (Class.java:2671)
    at java.lang.Class.getDeclaredConstructors (Class.java:2020)
    at com.google.inject.spi.InjectionPoint.forConstructorOf (InjectionPoint.java:245)
    at com.google.inject.internal.ConstructorBindingImpl.create (ConstructorBindingImpl.java:115)
    at com.google.inject.internal.InjectorImpl.createUninitializedBinding (InjectorImpl.java:706)
....
....
....
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  03:03 min
[INFO] Finished at: 2023-04-06T10:58:20+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M7:test (default-test) on project projects-test: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M7:test failed: A required class was missing while executing org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M7:test: org/apache/maven/surefire/api/testset/TestSetFailedException
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M7
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/Users/macusr/.m2/repo/org/apache/maven/plugins/maven-surefire-plugin/3.0.0-M7/maven-surefire-plugin-3.0.0-M7.jar
[ERROR] urls[1] = file:/Users/macusr/.m2/repo/org/apache/maven/surefire/surefire-junit47/2.19.1/surefire-junit47-2.19.1.jar
....
....
....
[ERROR] urls[16] = file:/Users/macusr/.m2/repo/org/ow2/asm/asm/9.2/asm-9.2.jar
[ERROR] urls[17] = file:/Users/macusr/.m2/repo/com/thoughtworks/qdox/qdox/2.0.1/qdox-2.0.1.jar
[ERROR] urls[18] = file:/Users/macusr/.m2/repo/org/apache/maven/surefire/surefire-shared-utils/3.0.0-M7/surefire-shared-utils-3.0.0-M7.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR] 
[ERROR] -----------------------------------------------------
[ERROR] : org.apache.maven.surefire.api.testset.TestSetFailedException
[ERROR] -> [Help 1]
[ERROR] 

Pom.xml

... <!-- Other dependencies -->
...
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <scope>test</scope>
</dependency>
<!-- TestNG dependency used for separate use-case -->
<dependency>
    <groupId>com.intuit.karate</groupId>
    <artifactId>karate-junit5</artifactId>
    <version>1.3.1</version>
    <scope>test</scope>
</dependency>
<!-- karate-junit5 which has junit-jupiter-api:5.7.2 & junit-jupiter-engine:5.7.2--> 
...
...
<build>
  <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M7</version>
    </plugin>
...
...

Previously we had maven-surefire-plugin:2.22.2 plugin with karate-junit5:1.3.1 and which causing the no test found issue

[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ fi-functonal-test ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  03:02 min
[INFO] Finished at: 2023-04-06T11:19:32+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project projects-test: No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
[ERROR] 

So, we have moved to recent version of maven-surefire-plugin:3.0.0-M7

Divya
  • 65
  • 4
  • sorry, this sounds like a complex `pom.xml` - so you have to follow this process if you need help: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Apr 06 '23 at 06:25
  • Do you combine `TestNG` and `Junit5` on purpose? It can cause this problem. – zforgo Apr 06 '23 at 07:36
  • More preciesely you are using three different and / or incompatible test frameworks in same project. Both `TestNG`, `JUnit5` (a.k.a. JUnit Jupiter) and `JUnit4` are on test classpath. Now, I strongly assume it's a missonfiguration. – zforgo Apr 06 '23 at 07:47
  • Actually, we have both integration-test with `TestNG` and Unit test with `Junit5` and not using any `Junit4` dependency & which is excluded if found other pom dependency. – Divya Apr 06 '23 at 09:56
  • To combine JUnit 5 with TestNG you should - and probably have to - use the TestNG engine for the JUnit platform. – johanneslink Apr 06 '23 at 11:57
  • Hi, @johanneslink How can we do that? if possible, please provide some examples – Divya Apr 07 '23 at 10:09
  • Have a look at https://github.com/junit-team/testng-engine – johanneslink Apr 07 '23 at 15:20
  • thanks @all , the actual issue with parent pom has junit4 dependency & maven surefire. And it got resolved with two maven profiles for junit 4 and 5. – Divya Apr 10 '23 at 10:35

0 Answers0