2013-02-12 57 views
4

我有一個項目,測試分爲單元和集成階段。我有它運行buildbot和問題是,即使在測試失敗maven返回代碼是0,所以buildbot構建是成功的。在失敗的測試中,Maven + Surefire返回代碼爲0

這是MVN集成測試的結果:

Results : 

Tests in error: 
Info about failed tests 

Tests run: 5, Failures: 0, Errors: 5, Skipped: 0 

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESSFUL 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 1 minute 19 seconds 
[INFO] Finished at: Tue Feb 12 09:43:53 UTC 2013 
[INFO] Final Memory: 36M/97M 
[INFO] ------------------------------------------------------------------------ 

$ echo $? 
0 

結果爲MVN安裝是沒有建立成功的部分相同 結果:

Tests in error: 
    Info about failed tests 

Tests run: 5, Failures: 0, Errors: 5, Skipped: 0 

$ echo $? 
0 

神火配置是這樣的:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.13</version> 
    <configuration> 
    <printSummary>true</printSummary> 
    <excludedGroups>com.testlib.IntegrationTest</excludedGroups> 
    </configuration> 
    <executions> 
    <execution> 
    <id>unit-tests</id> 
    <phase>test</phase> 
    <goals> 
     <goal>test</goal> 
    </goals> 
    <configuration> 
      <excludedGroups>com.testlib.IntegrationTest</excludedGroups> 
    </configuration> 
    </execution> 
    <execution> 
    <id>integration-tests</id> 
    <phase>integration-test</phase> 
    <goals> 
     <goal>test</goal> 
    </goals> 
    <configuration> 
     <includes> 
      <groups>com.testlib.IntegrationTest</groups> 
     </includes> 
     </configuration> 
    </execution> 
    </executions> 
</plugin> 

我讀過關於maven re的其他線程轉向代碼,但理論上相關的錯誤應該在我的Maven版本中修復(Apache Maven 2.2.1(rdebian-8))

有什麼方法可以改變這種行爲嗎?

更新: 作爲建議我試着與神火:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-failsafe-plugin</artifactId> 
    <version>2.13</version> 
    <dependencies> 
     <dependency> 
     <groupId>org.apache.maven.surefire</groupId> 
     <artifactId>surefire-junit47</artifactId> 
     <version>2.13</version> 
     </dependency> 
    </dependencies> 
    <configuration> 
     <groups>com.testlib.IntegrationTest</groups> 
    </configuration> 
    <executions> 
     <execution> 
      <goals> 
      <goal>integration-test</goal> 
      <goal>verify</goal> 
      </goals> 
      <configuration> 
       <includes> 
        <include>**/*.class</include> 
       </includes> 
      </configuration> 
     </execution> 
    </executions> 

我需要的神火,JUnit來避免初始化錯誤。

回答

2

我設法把它與兩種不同的配置工作,使用組並使用文件夾只用萬無一失的

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.13</version> 
    <configuration><excludedGroups>com.testlib.IntegrationTest</excludedGroups> 
    </configuration> 
    <executions> 
     <execution> 
      <id>integration-test</id> 
      <phase>integration-test</phase> 
      <goals> 
       goal>test</goal> 
      </goals> 
      <configuration> 
       <skip>false</skip> 
         <excludedGroups>com.biicode.testlib.UnitTest</excludedGroups> 
         <groups>com.testlib.IntegrationTest</groups> 
      </configuration> 
     </execution> 
    </executions> 

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <configuration> 
     <excludes> 
      <exclude>**/integration/*.java</exclude> 
     </excludes> 
    </configuration> 
    <executions> 
    <execution> 
     <id>integration-test</id> 
     <phase>integration-test</phase> 
     <goals> 
      <goal>test</goal> 
     </goals> 
     <configuration> 
     <skip>false</skip> 
     <excludes> 
      <exclude>none</exclude> 
     </excludes> 
     <includes> 
      <include>**/integration/*.java</include> 
     </includes> 
    </configuration> 
    </execution> 
    </executions> 
</plugin> 
1

如果是相同配置的父POM首先檢查:

<testFailureIgnore>true</testFailureIgnore> 

的地方......你可以通過檢查:

mvn help:effective-pom 

而且你正試圖與maven-surefire-plugin運行集成測試,簡直是錯誤的。對於集成測試,請使用maven-failsafe-plugin。另一件事是以正確的方式命名您的集成測試,如IT * .java,* IT.java等。

另一件事是您爲什麼使用這樣一箇舊的Maven版本檢查Maven 3.0.4。

對不起。監督你正在談論的集成測試。如果您正確使用maven-failsafe插件進行集成測試,它將包含一個特定目標verify ,該目標旨在檢查之後的集成測試結果。但是您需要通過執行塊單獨配置並綁定到特定的生命週期階段。

+0

不,我沒有testFailureIgnore這個,我會嘗試故障安全 – hithwen 2013-02-12 10:48:32

+0

啊...在我身邊的誤解,因爲你使用的集成測試需要單獨配置,就像我在最後一段中寫的那樣。 – khmarbaise 2013-02-12 11:18:39

+0

我嘗試了故障安全,並且仍然得到0 retcode – hithwen 2013-02-12 12:41:41

相關問題