如果我的集成测试失败,如何防止 Maven 组装我的 WAR?
How do I prevent Maven from assmebling my WAR if my integration tests fail?
我在 Mac Yosemite 上使用 Maven 3.3.3 和 Java 8。我有一堆集成测试,我有我的故障安全插件(v 2.18.1)这样设置......
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<reuseForks>true</reuseForks>
<argLine>-Xmx4096m -XX:MaxPermSize=512M -noverify -XX:-UseSplitVerifier ${itCoverageAgent}</argLine>
<skipTests>${skipAllTests}</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
然而,当我 运行 命令“mvn clean install”时,即使单元测试失败,构建也会继续组装 war。如果集成测试失败,如何防止进一步的 Maven activity?下面是我所看到的示例输出。请注意,即使在测试失败后,WAR 插件仍会继续 运行。
Results :
Failed tests:
MyProjectInstantLoginControllerIT.testInstantLoginSuccessNoCredentailsObj:245 View name is not equal to 'redirect:http://localhost:80/authenticate' but was 'redirect:http://localhost:80/home'
MyProjectInstantLoginControllerIT.testInstantLoginSuccessStudent:153 View name is not equal to 'redirect:http://localhost:80/authenticate' but was 'redirect:http://localhost:80/home'
MyProjectInstantLoginControllerIT.testInstantLoginSuccessTeacher:125 View name is not equal to 'redirect:http://localhost:80/authenticate' but was 'redirect:http://localhost:80/home'
MyProjectInstantLoginControllerIT.testInstantLoginSuccessWithApacheHeader:187 View name is not equal to 'redirect:http://localhost:80/authenticate' but was 'redirect:http://localhost:80/home'
Tests in error:
ClassController2IT.testUpdateClassWoSchedule:478->AbstractClassControllerTest.submitCreateClassForm:514 » LazyInitialization
Tests run: 157, Failures: 4, Errors: 1, Skipped: 4
[INFO]
[INFO] --- maven-war-plugin:2.6:war (default-war) @ my-module ---
[INFO] Packaging webapp
[INFO] Assembling webapp [my-module] in [/Users/davea/Documents/my_workspace/my-module/target/my-module]
[INFO] Dependency [Dependency {groupId=org.mainco.subco, artifactId=second-module, version=87.0.0-SNAPSHOT, type=jar}] has changed (was Dependency {groupId=org.mainco.subco, artifactId=second-module, version=87.0.0-SNAPSHOT, type=jar}).
[WARNING] File to remove [/Users/davea/Documents/my_workspace/my-module/target/my-module/WEB-INF/lib/second-module-87.0.0-SNAPSHOT.jar] has not been found
[INFO] Dependency [Dependency {groupId=org.springframework, artifactId=spring-core, version=3.2.11.RELEASE, type=jar}] has changed (was Dependency {groupId=org.springframework, artifactId=spring-core, version=3.2.11.RELEASE, type=jar}).
[WARNING] File to remove [/Users/davea/Documents/my_workspace/my-module/target/my-module/WEB-INF/lib/spring-core-3.2.11.RELEASE.jar] has not been found
[INFO] Dependency [Dependency {groupId=org.springframework.security.extensions, artifactId=spring-security-saml2-core, version=1.0.0.RC2, type=jar}] has changed (was Dependency {groupId=org.springframework.security.extensions, artifactId=spring-security-saml2-core, version=1.0.0.RC2, type=jar}).
[WARNING] File to remove [/Users/davea/Documents/my_workspace/my-module/target/my-module/WEB-INF/lib/spring-security-saml2-core-1.0.0.RC2.jar] has not been found
[INFO] Dependency [Dependency {groupId=org.opensaml, artifactId=opensaml, version=2.6.1, type=jar}] has changed (was Dependency {groupId=org.opensaml, artifactId=opensaml, version=2.6.1, type=jar}).
[WARNING] File to remove [/Users/davea/Documents/my_workspace/my-module/target/my-module/WEB-INF/lib/opensaml-2.6.1.jar] has not been found
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/davea/Documents/my_workspace/my-module/src/main/webapp]
[INFO] Webapp assembled in [5454 msecs]
[INFO] Building war: /Users/davea/Documents/my_workspace/my-module/target/my-module.war
[INFO]
[INFO] --- maven-failsafe-plugin:2.18.1:verify (default) @ my-module ---
[INFO] Failsafe report directory: /Users/davea/Documents/my_workspace/my-module/target/failsafe-reports
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:17 min
[INFO] Finished at: 2015-11-09T11:23:47-06:00
[INFO] Final Memory: 48M/792M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.18.1:verify (default) on project my-module: There are test failures.
[ERROR]
[ERROR] Please refer to /Users/davea/Documents/my_workspace/my-module/target/failsafe-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
您还没有指定任何您想要 failsafe
插件实现 运行 目标的阶段。默认情况下,目标 integration-test
和 verify
绑定到 default
生命周期的 integration-test
和 verify
阶段。
回想一下,这些阶段发生在 package
阶段完成后(参考 the life cycle references),因此根据您的配置,您不会以任何方式影响 package
阶段- 您在 package
阶段后的目标 运行(即在该阶段设定为 运行 的目标 - maven-war-plugin:2.6:war
是一个)已完成。
您可以尝试 运行 进行集成测试并在 package
阶段之前验证它们,如果您真的想要的话,可以通过在 [=21] 中为您的目标指定适当的阶段=] 你已经在你的 OP 中展示了。
与问题无关,maven-failsafe-plugin
插件旨在针对集成测试并将构建失败与实际集成测试结果分离。您可以通过验证集成测试结果来绕过它。
引用自 FAQ:
What is the difference between maven-failsafe-plugin and
maven-surefire-plugin?
maven-surefire-plugin
is designed for running unit tests and if any of the tests fail then it will fail the build immediately.
maven-failsafe-plugin
is designed for running integration tests, and decouples failing the build if there are test failures from
actually running the tests.
关于此主题的进一步 notes:
If you use the Surefire Plugin for running tests, then when you have a
test failure, the build will stop at the integration-test phase and
your integration test environment will not have been torn down
correctly.
The Failsafe Plugin is used during the integration-test and verify
phases of the build lifecycle to execute the integration tests of an
application. The Failsafe Plugin will not fail the build during the
integration-test phase, thus enabling the post-integration-test phase
to execute.
我在 Mac Yosemite 上使用 Maven 3.3.3 和 Java 8。我有一堆集成测试,我有我的故障安全插件(v 2.18.1)这样设置......
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<reuseForks>true</reuseForks>
<argLine>-Xmx4096m -XX:MaxPermSize=512M -noverify -XX:-UseSplitVerifier ${itCoverageAgent}</argLine>
<skipTests>${skipAllTests}</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
然而,当我 运行 命令“mvn clean install”时,即使单元测试失败,构建也会继续组装 war。如果集成测试失败,如何防止进一步的 Maven activity?下面是我所看到的示例输出。请注意,即使在测试失败后,WAR 插件仍会继续 运行。
Results :
Failed tests:
MyProjectInstantLoginControllerIT.testInstantLoginSuccessNoCredentailsObj:245 View name is not equal to 'redirect:http://localhost:80/authenticate' but was 'redirect:http://localhost:80/home'
MyProjectInstantLoginControllerIT.testInstantLoginSuccessStudent:153 View name is not equal to 'redirect:http://localhost:80/authenticate' but was 'redirect:http://localhost:80/home'
MyProjectInstantLoginControllerIT.testInstantLoginSuccessTeacher:125 View name is not equal to 'redirect:http://localhost:80/authenticate' but was 'redirect:http://localhost:80/home'
MyProjectInstantLoginControllerIT.testInstantLoginSuccessWithApacheHeader:187 View name is not equal to 'redirect:http://localhost:80/authenticate' but was 'redirect:http://localhost:80/home'
Tests in error:
ClassController2IT.testUpdateClassWoSchedule:478->AbstractClassControllerTest.submitCreateClassForm:514 » LazyInitialization
Tests run: 157, Failures: 4, Errors: 1, Skipped: 4
[INFO]
[INFO] --- maven-war-plugin:2.6:war (default-war) @ my-module ---
[INFO] Packaging webapp
[INFO] Assembling webapp [my-module] in [/Users/davea/Documents/my_workspace/my-module/target/my-module]
[INFO] Dependency [Dependency {groupId=org.mainco.subco, artifactId=second-module, version=87.0.0-SNAPSHOT, type=jar}] has changed (was Dependency {groupId=org.mainco.subco, artifactId=second-module, version=87.0.0-SNAPSHOT, type=jar}).
[WARNING] File to remove [/Users/davea/Documents/my_workspace/my-module/target/my-module/WEB-INF/lib/second-module-87.0.0-SNAPSHOT.jar] has not been found
[INFO] Dependency [Dependency {groupId=org.springframework, artifactId=spring-core, version=3.2.11.RELEASE, type=jar}] has changed (was Dependency {groupId=org.springframework, artifactId=spring-core, version=3.2.11.RELEASE, type=jar}).
[WARNING] File to remove [/Users/davea/Documents/my_workspace/my-module/target/my-module/WEB-INF/lib/spring-core-3.2.11.RELEASE.jar] has not been found
[INFO] Dependency [Dependency {groupId=org.springframework.security.extensions, artifactId=spring-security-saml2-core, version=1.0.0.RC2, type=jar}] has changed (was Dependency {groupId=org.springframework.security.extensions, artifactId=spring-security-saml2-core, version=1.0.0.RC2, type=jar}).
[WARNING] File to remove [/Users/davea/Documents/my_workspace/my-module/target/my-module/WEB-INF/lib/spring-security-saml2-core-1.0.0.RC2.jar] has not been found
[INFO] Dependency [Dependency {groupId=org.opensaml, artifactId=opensaml, version=2.6.1, type=jar}] has changed (was Dependency {groupId=org.opensaml, artifactId=opensaml, version=2.6.1, type=jar}).
[WARNING] File to remove [/Users/davea/Documents/my_workspace/my-module/target/my-module/WEB-INF/lib/opensaml-2.6.1.jar] has not been found
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/davea/Documents/my_workspace/my-module/src/main/webapp]
[INFO] Webapp assembled in [5454 msecs]
[INFO] Building war: /Users/davea/Documents/my_workspace/my-module/target/my-module.war
[INFO]
[INFO] --- maven-failsafe-plugin:2.18.1:verify (default) @ my-module ---
[INFO] Failsafe report directory: /Users/davea/Documents/my_workspace/my-module/target/failsafe-reports
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:17 min
[INFO] Finished at: 2015-11-09T11:23:47-06:00
[INFO] Final Memory: 48M/792M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.18.1:verify (default) on project my-module: There are test failures.
[ERROR]
[ERROR] Please refer to /Users/davea/Documents/my_workspace/my-module/target/failsafe-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
您还没有指定任何您想要 failsafe
插件实现 运行 目标的阶段。默认情况下,目标 integration-test
和 verify
绑定到 default
生命周期的 integration-test
和 verify
阶段。
回想一下,这些阶段发生在 package
阶段完成后(参考 the life cycle references),因此根据您的配置,您不会以任何方式影响 package
阶段- 您在 package
阶段后的目标 运行(即在该阶段设定为 运行 的目标 - maven-war-plugin:2.6:war
是一个)已完成。
您可以尝试 运行 进行集成测试并在 package
阶段之前验证它们,如果您真的想要的话,可以通过在 [=21] 中为您的目标指定适当的阶段=] 你已经在你的 OP 中展示了。
与问题无关,maven-failsafe-plugin
插件旨在针对集成测试并将构建失败与实际集成测试结果分离。您可以通过验证集成测试结果来绕过它。
引用自 FAQ:
What is the difference between maven-failsafe-plugin and maven-surefire-plugin?
maven-surefire-plugin
is designed for running unit tests and if any of the tests fail then it will fail the build immediately.
maven-failsafe-plugin
is designed for running integration tests, and decouples failing the build if there are test failures from actually running the tests.
关于此主题的进一步 notes:
If you use the Surefire Plugin for running tests, then when you have a test failure, the build will stop at the integration-test phase and your integration test environment will not have been torn down correctly.
The Failsafe Plugin is used during the integration-test and verify phases of the build lifecycle to execute the integration tests of an application. The Failsafe Plugin will not fail the build during the integration-test phase, thus enabling the post-integration-test phase to execute.