如果集成测试失败,如何防止Maven破坏我的WAR?

时间:2015-11-09 17:46:38

标签: maven maven-3 integration-testing maven-failsafe-plugin

我在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”时,即使我的单元测试失败,构建仍继续组装战争。如果集成测试失败,如何防止进一步的Maven活动?以下是我所看到的示例输出。请注意,即使在测试失败后,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

1 个答案:

答案 0 :(得分:1)

您尚未指定任何您希望failsafe插件运行其目标的阶段。默认情况下,目标integration-testverify绑定到integration-test生命周期的verifydefault阶段。

回想一下,package阶段完成后会发生这些阶段(请参阅the life cycle references),因此,根据您的配置,您不会以任何方式影响package阶段 - 您的目标在package阶段之后运行(即设定在该阶段运行的目标 - maven-war-plugin:2.6:war为1)已完成。

您可以尝试运行集成测试并在package阶段之前验证它们,如果这是您真正想要的,请在您显示的<execution>中为您的目标指定适当的阶段你的OP。

与此问题无关,maven-failsafe-plugin插件旨在针对集成测试并将构建失败与实际集成测试结果分离。您可以通过验证集成测试结果来解决这个问题。

以下是FAQ

的引用
  

maven-failsafe-plugin和。之间的区别是什么?   行家-万无一失-插件?

     

maven-surefire-plugin用于运行单元测试,如果任何测试失败,则会立即使构建失败。

     

maven-failsafe-plugin用于运行集成测试,如果出现测试失败,则解耦会导致构建失败   实际上正在运行测试。

关于此主题的进一步notes

  

如果你使用Surefire插件运行测试,那么当你有一个   测试失败,构建将在集成测试阶段停止   您的集成测试环境不会被拆除   正确。

     

在集成测试和验证期间使用Failsafe插件   构建生命周期的各个阶段,用于执行一个集成测试   应用。故障安全插件不会在构建过程中失败   集成测试阶段,从而实现集成后测试阶段   执行。