2015-11-09 22 views
0

我在Mac Yosemite上使用Java 8的Maven 3.3.3。我有一大堆的集成測試,我有我的故障安全插件(V 2.18.1)設置爲這樣......如果我的集成測試失敗,我該如何防止Maven攻擊我的WAR?

    <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全新安裝,」即使我失敗了單元測試,構建繼續組裝戰爭。如果我的集成測試失敗,我如何防止進一步的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

事實上,你的構建打包戰爭不應該影響你的管道。構建明確標記爲失敗,並且應該防止發生任何後續行爲。你不能忽略這場戰爭嗎? – iwein

回答

1

您還沒有指定任何階段(S)你想failsafe插件來運行其目標。默認情況下,目標integration-testverify綁定到default生命週期的integration-testverify階段。

回想一下,package階段結束(參見the life cycle references),之後會出現這些不同的階段你所擁有的配置,你是不以任何方式影響的package階段 - 你的目標package階段之後運行(即目標設定在這個階段運行 - maven-war-plugin:2.6:war是一個)是完整的。

你可以嘗試運行集成測試和package階段之前驗證他們,如果這是你真的在<execution>您在OP已經證明對指定目標的適當階段(一個或多個)想要什麼。


無關的問題,maven-failsafe-plugin插件旨在針對集成測試和解耦從實際的集成測試結果的構建失敗。您可以通過驗證集成測試結果來解決這個問題。

下面是來自FAQ報價:

是什麼Maven的故障保護,插件和 Maven的萬無一失,插件之間的區別?

maven-surefire-plugin是專爲運行單元測試,如果任何測試失敗,那麼它會立即失敗構建。

maven-failsafe-plugin專爲運行集成測試而設計,並且在實際運行測試的 存在測試失敗的情況下解耦構建失敗。

而且在這個問題上notes

如果使用Surefire插件運行測試,然後當你有一個 測試失敗,該版本將停止在集成測試階段和 您整合測試環境不會被正確拆除 。

故障安全插件是集成測試期間使用和驗證構建的生命週期的階段 以執行 應用的集成測試。故障安全插件在 集成測試階段不會使構建失敗,從而使集成後測試階段 能夠執行。

+1

刪除我的答案,因爲它與你的相似。 – Daniel

相關問題