How to run JUnit 5 @Suite tests via Maven Surefire #2753
-
Hi Team, I am unable to run Junit 5 Test Suite (@suite) using the Maven command line. It always says, Total tests 0. I have tried various options/configurations from the maven-surefire plugin v3.0.0-M5. Sample Test Suite:
1 Option: I have used Junit 5 Paralallism configuration inside the Surefire plugin as below to run all the tests from inside the test suite in parallel. None of the tests was picked up. It says no tests to run.
2nd Option: Using Maven Surefire Forks to run the tests inside the test suite in parallel with the below configuration from the POM.xml file. And used mvn -Dgroups=Test command to run the tests using Tags. No tests were detected. Response from Maven
POM.XML
3rd Option: I have used the same configuration as like above POM.xml, but I have used Test Cases Tag name instead of Test Suite Tag name. Now the test cases were run in sequential, however, the test suite still shows 0 Total Test Cases. Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
Converted into a discussion, as it is not an issue with a component of JUnit. I'll try to find an answer later this week. Although I think that the current implementation of Surefire's JUnit Platform Provider is not capable of running suites out-of-the-box. Note to myself: Does it work with https://github.com/sormuras/junit-platform-maven-plugin ? |
Beta Was this translation helpful? Give feedback.
-
Taking https://github.com/junit-team/junit5-samples/blob/main/junit5-jupiter-starter-maven/pom.xml as a common base and applying the following patch: Index: junit5-jupiter-starter-maven/pom.xml
===================================================================
diff --git a/junit5-jupiter-starter-maven/pom.xml b/junit5-jupiter-starter-maven/pom.xml
--- a/junit5-jupiter-starter-maven/pom.xml (revision 0aa3e933a3e90d3d6175c8f1da0c63283348d263)
+++ b/junit5-jupiter-starter-maven/pom.xml (date 1635318636736)
@@ -31,6 +31,11 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-suite</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -42,6 +47,11 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
+ <configuration>
+ <includes>
+ <include>**/MySuite.java</include>
+ </includes>
+ </configuration>
</plugin>
</plugins>
</build>
Index: junit5-jupiter-starter-maven/src/test/java/com/example/MySuite.java
===================================================================
diff --git a/junit5-jupiter-starter-maven/src/test/java/com/example/MySuite.java b/junit5-jupiter-starter-maven/src/test/java/com/example/MySuite.java
new file mode 100644
--- /dev/null (date 1635318673680)
+++ b/junit5-jupiter-starter-maven/src/test/java/com/example/MySuite.java (date 1635318673680)
@@ -0,0 +1,9 @@
+package com.example;
+
+import org.junit.platform.suite.api.SelectPackages;
+import org.junit.platform.suite.api.Suite;
+
+@Suite
+@SelectPackages("com.example.project")
+public class MySuite {
+} Running
Ergo, running As Marc mentioned here #2749 (comment) Surefire doesn't support running tests in parallel on the JUnit Platform. Answer to myself: sormuras/junit-platform-maven-plugin@75be966 ✅ |
Beta Was this translation helpful? Give feedback.
Taking https://github.com/junit-team/junit5-samples/blob/main/junit5-jupiter-starter-maven/pom.xml as a common base and applying the following patch: