You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2026/07/31 03:54:17 UTC

(maven-surefire) branch master updated: [SUREFIRE-823] Decouple -DskipTests from Failsafe plugin (#3371)

This is an automated email from the ASF dual-hosted git repository.

olamy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git


The following commit(s) were added to refs/heads/master by this push:
     new 045f0b523 [SUREFIRE-823] Decouple -DskipTests from Failsafe plugin (#3371)
045f0b523 is described below

commit 045f0b523f6fecc784a27d819883ea4c856b2a10
Author: Olivier Lamy <ol...@apache.org>
AuthorDate: Fri Jul 31 13:54:12 2026 +1000

    [SUREFIRE-823] Decouple -DskipTests from Failsafe plugin (#3371)
    
    * [SUREFIRE-823] Decouple -DskipTests from Failsafe plugin
---
 .../maven/plugin/failsafe/IntegrationTestMojo.java |  16 ++++
 .../apache/maven/plugin/failsafe/VerifyMojo.java   |  12 ++-
 .../plugin/surefire/AbstractSurefireMojo.java      |   7 +-
 .../src/site/apt/examples/skipping-tests.apt.vm    |  12 ++-
 .../jiras/Surefire1766SkipTestsDecoupledIT.java    | 100 +++++++++++++++++++++
 .../resources/failsafe-1766-skip-decoupled/pom.xml |  66 ++++++++++++++
 .../src/test/java/MyIT.java                        |  29 ++++++
 .../src/test/java/MyTest.java                      |  29 ++++++
 8 files changed, 263 insertions(+), 8 deletions(-)

diff --git a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
index a22be5989..8b3a04653 100644
--- a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
+++ b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
@@ -71,6 +71,22 @@ public class IntegrationTestMojo extends AbstractSurefireMojo {
     @Parameter(property = "skipITs")
     private boolean skipITs;
 
+    /**
+     * Set this to "true" to skip running integration tests, but still compile them. Its use is NOT RECOMMENDED, but
+     * quite convenient on occasion.
+     * <p>
+     * Unlike Surefire's {@code skipTests}, this Failsafe parameter is <strong>not</strong> bound to the
+     * {@code skipTests} user property. Use {@code -DskipITs} on the command line to skip integration tests,
+     * or {@code -Dmaven.test.skip} to skip both unit and integration tests. The {@code <skipTests>} element
+     * is still honored when set explicitly in the plugin {@code <configuration>}.
+     *
+     * @since 3.6.0
+     * @deprecated use {@code skipITs} instead
+     */
+    @Deprecated
+    @Parameter
+    private boolean skipTests;
+
     /**
      * Base directory where all reports are written to.
      */
diff --git a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java
index 7d258466d..92a0a329f 100644
--- a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java
+++ b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/VerifyMojo.java
@@ -54,12 +54,18 @@
 public class VerifyMojo extends AbstractMojo implements SurefireReportParameters {
 
     /**
-     * Set this to 'true' to skip running tests, but still compile them. Its use is NOT RECOMMENDED, but quite
-     * convenient on occasion.
+     * Set this to 'true' to skip verifying integration test results.
+     * <p>
+     * Unlike Surefire's {@code skipTests}, this Failsafe parameter is <strong>not</strong> bound to the
+     * {@code skipTests} user property. Use {@code -DskipITs} on the command line to skip integration tests
+     * (including this verification step), or {@code -Dmaven.test.skip} to skip everything. The
+     * {@code <skipTests>} element is still honored when set explicitly in the plugin {@code <configuration>}.
      *
      * @since 2.4
+     * @deprecated use {@code skipITs} instead
      */
-    @Parameter(property = "skipTests")
+    @Deprecated
+    @Parameter
     private boolean skipTests;
 
     /**
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
index 676e9cdc6..bec3bc62c 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
@@ -193,8 +193,11 @@ public abstract class AbstractSurefireMojo extends AbstractMojo implements Suref
     /**
      * Set this to "true" to skip running tests, but still compile them. Its use is NOT RECOMMENDED, but quite
      * convenient on occasion.<br>
-     * Failsafe plugin deprecated the parameter {@code skipTests} and the parameter will be removed in
-     * <i>Failsafe 3.0.0</i> as it is a source of conflicts between Failsafe and Surefire plugin.
+     * <p>
+     * As of Failsafe 3.6.0, the Failsafe plugin no longer binds its own {@code skipTests} parameter to the
+     * {@code skipTests} user property, so {@code -DskipTests=true} now skips only Surefire (unit tests) while
+     * leaving Failsafe (integration tests) untouched. Use {@code -DskipITs} to skip integration tests, or
+     * {@code -Dmaven.test.skip} to skip both.
      *
      * @since 2.4
      */
diff --git a/maven-surefire-plugin/src/site/apt/examples/skipping-tests.apt.vm b/maven-surefire-plugin/src/site/apt/examples/skipping-tests.apt.vm
index 7b8e3a8f1..5b0613643 100644
--- a/maven-surefire-plugin/src/site/apt/examples/skipping-tests.apt.vm
+++ b/maven-surefire-plugin/src/site/apt/examples/skipping-tests.apt.vm
@@ -88,9 +88,15 @@ mvn install -DskipTests
 mvn install -DskipTests
 +---+
 
- Since <<<skipTests>>> is also supported by the ${thatPlugin} Plugin, this will have the effect
- of not running any tests.  If, instead, you want to skip only the integration tests
- being run by the ${thisPlugin} Plugin, you would use the <<<skipITs>>> property instead:
+#{if}(${project.artifactId}=="maven-surefire-plugin")
+ The <<<-DskipTests>>> command-line property only skips tests run by the ${thisPlugin} Plugin and
+ does <<not>> skip the integration tests run by the ${thatPlugin} Plugin (since 3.6.0).
+ To skip integration tests from the command line use the <<<skipITs>>> property:
+#{else}
+ The <<<-DskipTests>>> command-line property only skips tests run by the Surefire Plugin and
+ does <<not>> skip the integration tests run by the ${thisPlugin} Plugin (since 3.6.0).
+ To skip integration tests from the command line use the <<<skipITs>>> property:
+#{end}
 
 +---+
 mvn install -DskipITs
diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1766SkipTestsDecoupledIT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1766SkipTestsDecoupledIT.java
new file mode 100644
index 000000000..7933d348a
--- /dev/null
+++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1766SkipTestsDecoupledIT.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.surefire.its.jiras;
+
+import org.apache.maven.surefire.its.fixture.FailsafeOutputValidator;
+import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
+import org.apache.maven.surefire.its.fixture.SurefireLauncher;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Verifies that {@code -DskipTests} only skips Surefire (unit tests) and no longer skips
+ * Failsafe (integration tests), while {@code -DskipITs} and {@code -Dmaven.test.skip}
+ * continue to control Failsafe execution.
+ *
+ * @see <a href="https://github.com/apache/maven-surefire/issues/1766">Surefire #1766 / SUREFIRE-823</a>
+ */
+public class Surefire1766SkipTestsDecoupledIT extends SurefireJUnit4IntegrationTestCase {
+
+    @Test
+    public void noSkipShouldRunBoth() {
+        FailsafeOutputValidator validator = unpack().executeVerify();
+
+        validator.verifyErrorFreeLog();
+        // Baseline: with no skip flag, both Surefire (unit tests) and Failsafe (integration tests) run
+        validator.assertTestSuiteResults(1, 0, 0, 0);
+        validator.assertIntegrationTestSuiteResults(1, 0, 0, 0);
+    }
+
+    @Test
+    public void skipTestsShouldOnlySkipSurefireNotFailsafe() {
+        FailsafeOutputValidator validator =
+                unpack().sysProp("skipTests", "true").executeVerify();
+
+        validator.verifyErrorFreeLog();
+        // Surefire (unit tests) is skipped: the surefire skip log message is emitted
+        // and no surefire-reports directory is produced.
+        validator.verifyTextInLog("Tests are skipped.");
+        assertFalse(
+                validator.getSubFile("target/surefire-reports").exists(),
+                "surefire-reports should not exist when -DskipTests is used");
+        // Failsafe (integration tests) still runs the IT
+        assertTrue(
+                validator.getSubFile("target/failsafe-reports").exists(),
+                "failsafe-reports should exist when -DskipTests is used (ITs still run)");
+        validator.assertIntegrationTestSuiteResults(1, 0, 0, 0);
+    }
+
+    @Test
+    public void skipITsShouldSkipFailsafeOnly() {
+        FailsafeOutputValidator validator = unpack().sysProp("skipITs", "true").executeVerify();
+
+        validator.verifyErrorFreeLog();
+        // Surefire still runs the unit test
+        validator.assertTestSuiteResults(1, 0, 0, 0);
+        assertTrue(
+                validator.getSubFile("target/surefire-reports").exists(),
+                "surefire-reports should exist when -DskipITs is used (unit tests still run)");
+        // Failsafe is skipped: no failsafe-reports directory is produced
+        assertFalse(
+                validator.getSubFile("target/failsafe-reports").exists(),
+                "failsafe-reports should not exist when -DskipITs is used");
+    }
+
+    @Test
+    public void mavenTestSkipShouldSkipBoth() {
+        FailsafeOutputValidator validator =
+                unpack().sysProp("maven.test.skip", "true").executeVerify();
+
+        validator.verifyErrorFreeLog();
+        assertFalse(
+                validator.getSubFile("target/surefire-reports").exists(),
+                "surefire-reports should not exist when -Dmaven.test.skip is used");
+        assertFalse(
+                validator.getSubFile("target/failsafe-reports").exists(),
+                "failsafe-reports should not exist when -Dmaven.test.skip is used");
+    }
+
+    private SurefireLauncher unpack() {
+        return unpack("failsafe-1766-skip-decoupled");
+    }
+}
diff --git a/surefire-its/src/test/resources/failsafe-1766-skip-decoupled/pom.xml b/surefire-its/src/test/resources/failsafe-1766-skip-decoupled/pom.xml
new file mode 100644
index 000000000..090253e85
--- /dev/null
+++ b/surefire-its/src/test/resources/failsafe-1766-skip-decoupled/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>localhost</groupId>
+    <artifactId>failsafe-1766-skip-decoupled</artifactId>
+    <version>1.0</version>
+    <name>failsafe-1766-skip-decoupled</name>
+
+    <properties>
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <version>5.10.2</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>${surefire.version}</version>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-failsafe-plugin</artifactId>
+                <version>${surefire.version}</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>integration-test</goal>
+                            <goal>verify</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/surefire-its/src/test/resources/failsafe-1766-skip-decoupled/src/test/java/MyIT.java b/surefire-its/src/test/resources/failsafe-1766-skip-decoupled/src/test/java/MyIT.java
new file mode 100644
index 000000000..3e7c1181a
--- /dev/null
+++ b/surefire-its/src/test/resources/failsafe-1766-skip-decoupled/src/test/java/MyIT.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class MyIT {
+    @Test
+    public void testIntegration() {
+        assertTrue(true);
+    }
+}
diff --git a/surefire-its/src/test/resources/failsafe-1766-skip-decoupled/src/test/java/MyTest.java b/surefire-its/src/test/resources/failsafe-1766-skip-decoupled/src/test/java/MyTest.java
new file mode 100644
index 000000000..e74948fb4
--- /dev/null
+++ b/surefire-its/src/test/resources/failsafe-1766-skip-decoupled/src/test/java/MyTest.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class MyTest {
+    @Test
+    public void testUnit() {
+        assertTrue(true);
+    }
+}