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 a22be5989f..8b3a04653a 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. + *

+ * Unlike Surefire's {@code skipTests}, this Failsafe parameter is not 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 } element + * is still honored when set explicitly in the plugin {@code }. + * + * @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 7d258466df..92a0a329f4 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. + *

+ * Unlike Surefire's {@code skipTests}, this Failsafe parameter is not 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 } element is still honored when set explicitly in the plugin {@code }. * * @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 676e9cdc6c..bec3bc62c6 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.
- * Failsafe plugin deprecated the parameter {@code skipTests} and the parameter will be removed in - * Failsafe 3.0.0 as it is a source of conflicts between Failsafe and Surefire plugin. + *

+ * 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 7b8e3a8f12..2610758138 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 +---+ +#{if}(${project.artifactId}=="maven-surefire-plugin") Since <<>> 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 <<>> property instead: + of not running any tests. If, instead, you want to skip only the integration tests + being run by the ${thatPlugin} Plugin, you would use the <<>> property instead: +#{else} + The <<<-DskipTests>>> command-line property only skips tests run by the Surefire Plugin and + does <> skip the integration tests run by the ${thisPlugin} Plugin (since 3.6.0). + To skip integration tests from the command line use the <<>> 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 0000000000..a0839a5a8f --- /dev/null +++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1766SkipTestsDecoupledIT.java @@ -0,0 +1,83 @@ +/* + * 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; + +/** + * 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 Surefire #1766 / SUREFIRE-823 + */ +public class Surefire1766SkipTestsDecoupledIT extends SurefireJUnit4IntegrationTestCase { + + @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 + 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); + // 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 0000000000..090253e85a --- /dev/null +++ b/surefire-its/src/test/resources/failsafe-1766-skip-decoupled/pom.xml @@ -0,0 +1,66 @@ + + + + + 4.0.0 + + localhost + failsafe-1766-skip-decoupled + 1.0 + failsafe-1766-skip-decoupled + + + 1.8 + 1.8 + + + + + org.junit.jupiter + junit-jupiter + 5.10.2 + test + + + + + + + maven-surefire-plugin + ${surefire.version} + + + org.apache.maven.plugins + maven-failsafe-plugin + ${surefire.version} + + + + integration-test + verify + + + + + + + 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 0000000000..3e7c1181a8 --- /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 0000000000..e74948fb48 --- /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); + } +}