2012-09-05 28 views
11

我想使用maven-failsafe-plugin來運行一些集成測試。如果任何測試失敗,我希望Maven失敗構建而不是BUILD BUILD SUCCESS。maven-failsafe-plugin失敗並建立成功?

Tests run: 103, Failures: 1, Errors: 0, Skipped: 26 
[INFO] BUILD SUCCESS* 


如何我可以配置它,建造不是成功是什麼?

我的故障安全插件配置爲:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-failsafe-plugin</artifactId> 
    <version>${failsafe.version}</version> 
    <configuration> 
     <systemProperties> 
      <CI_INTEGRATION_OVERRIDE_PATH>${basedir}/..</CI_INTEGRATION_OVERRIDE_PATH> 
     </systemProperties> 
     <includes> 
      <include>**/integration/**/*.java</include> 
     </includes> 
     <excludes> 
      <exclude>**/integration/**/*TestSuite.java</exclude> 
     </excludes> 
    </configuration> 
    <executions> 
     <execution> 
      <id>integration-test</id> 
      <goals> 
       <goal>integration-test</goal> 
       <goal>verify</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 
+0

您使用的是哪個版本的maven-failsafe-plugin?哪個Maven版本?你是怎麼叫mvn來運行集成測試的? – khmarbaise

+2

關於「Maven - Users」,請參見[此郵件主題](http://maven.40175.n5.nabble.com/Failing-a-build-with-maven-failsafe-plugin-td3199308.html)。 –

+0

MAVEN CALL:mvn clean install -P罐故障安全:集成測試-e 2.12 MAVEN 3.16 – Fawi

回答

1

解決方案。

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <configuration> 
    <skip>true</skip> 
    </configuration> 
    <executions> 
    <execution> 
     <id>unit-test</id> 
     <phase>test</phase> 
     <goals> 
     <goal>test</goal> 
     </goals> 
     <configuration> 
     <skip>false</skip> 
     <excludes> 
      <exclude>**/*IntegrationTest.java</exclude> 
     </excludes> 
     </configuration> 
     </execution> 
     <execution> 
     <id>integration-test</id> 
     <phase>integration-test</phase> 
     <goals> 
      <goal>test</goal> 
     </goals> 
     <configuration> 
      <skip>false</skip> 
      <enableAssertions>false</enableAssertions> 
      <includes> 
      <include>**/*IntegrationTest.java</include> 
      </includes> 
      <systemPropertyVariables> 
      <integration>${integration}</integration> 
      </systemPropertyVariables> 
     </configuration> 
     </execution> 
    </executions> 
</plugin> 
+6

這個答案是用surefire插件取代故障安全插件。 – Andrew

1

既然你正在運行mvn clean installintegration-testverify階段都應該執行。根據故障安全插件文檔failsafe:integration-testfailsafe:verify的目標是綁定到這些階段,所以我不認爲需要額外致電failsafe:integration-test

這就是說,但我不確定我信任故障安全插件文檔。我爲answered a similar question今年早些時候的人。事實證明,他必須明確地將每個目標綁定到正確的階段,然後按預期工作失敗。可能值得一試。

+0

我找到了解決方案,我可以使用maven-surefire插件進行集成測試。 – Fawi

7

正如Andrew指出的那樣,正確的解決方案是按照預期使用失效保護。集成測試目標是專門設計的,不會使構建失敗。如果您想要構建失敗,請致電mvn verifymvn failsafe:verify

+1

我同意你的回答。它的測試目標是設計不失敗。 「我的目​​標是不同的,我想製作一本自以爲是的軟件,我更喜歡約定優於配置的概念。」正如Jason van Zyl在Maven文章的歷史中引用的那樣。遵守慣例總是很好的,而不是剽竊它來做非設計的東西。 – NewUser

+1

我經常發現,Maven作者的意圖似乎與一個理智的人嘗試使用它的方式直接相抵觸。 – cbmanica