2013-02-25 107 views
2

我有一個Jenkins平臺,它調用maven進行單元測試(與surefire插件)和集成測試(與安全故障插件)。當集成測試出現錯誤時,Jenkins認爲構建成功。這種行爲是否正常?我寧願它認爲構建不穩定。更一般地說,你是否知道詹金斯如何閱讀並解釋構建的結果,將構建視爲成功或不穩定?我在網上的某個地方讀到,必須將故障安全報告重定向到肯定的報告路徑。我做了id,但問題仍然存在。詹金斯+硒測試與故障安全插件

的pom.xml:

[...] 
    <plugin> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.10</version> 
     <configuration> 
     <disableXmlReport>false</disableXmlReport> 
     </configuration> 
     <executions> 
     <execution> 
      <id>default-test</id> 
      <phase>test</phase> 
      <configuration> 
      <includes> 
       <include>**/tests/**</include> 
      </includes> 
      <excludes> 
       <exclude>**/testsIntegration/**</exclude> 
      </excludes> 
      </configuration> 
     </execution> 
     </executions> 
    </plugin> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-failsafe-plugin</artifactId> 
     <version>2.7.2</version> 
     <configuration> 
     <disableXmlReport>false</disableXmlReport> 
     <reportsDirectory>${basedir}/target/surefire-reports</reportsDirectory> 
     <includes> 
      <include>com/acelys/conventionsJuridiques/*.java</include> 
      <!-- ... inclure les tests Selenium --> 
     </includes> 
     </configuration> 
     <executions> 
     <execution> 
      <id>integration-test</id> 
      <phase>integration-test</phase> 
      <goals> 
      <goal>integration-test</goal> 
      </goals> 
      <configuration> 
      <includes> 
       <include>**/testsIntegration/**</include> 
      </includes> 
      <excludes> 
       <exclude>**/tests/**</exclude> 
      </excludes> 
      </configuration> 
     </execution> 
     </executions> 
    </plugin> 
[...] 

輸出詹金斯:

[...] 
mojoStarted org.apache.maven.plugins:maven-failsafe-plugin:2.7.2(integration-test) 
[INFO] 
[INFO] --- maven-failsafe-plugin:2.7.2:integration-test (integration-test) @ BaseContrats --- 
[INFO] Failsafe report directory: C:\jenkins_home\workspace\Base Contrats EXT JS MAVEN\target\surefire-reports 

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 
Running com.acelys.conventionsJuridiques.testsIntegration.connexion.TestConnexion 

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 23.971 sec <<< FAILURE! 

Results : 

Failed tests: 
    testHomePage(com.acelys.conventionsJuridiques.testsIntegration.connexion.TestConnexion) 

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

[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! 
mojoSucceeded org.apache.maven.plugins:maven-failsafe-plugin:2.7.2(integration-test) 
mojoStarted org.apache.tomcat.maven:tomcat6-maven-plugin:2.1-SNAPSHOT(tomcat-shutdown) 
[INFO] 
[INFO] --- tomcat6-maven-plugin:2.1-SNAPSHOT:shutdown (tomcat-shutdown) @ BaseContrats --- 
25 févr. 2013 09:32:08 org.apache.coyote.http11.Http11Protocol destroy 
INFO: Stopping Coyote HTTP/1.1 on http-8080 
25 févr. 2013 09:32:08 org.apache.catalina.core.ApplicationContext log 
INFO: Closing Spring root WebApplicationContext 
25 févr. 2013 09:32:08 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc 

mojoSucceeded org.apache.tomcat.maven:tomcat6-maven-plugin:2.1-SNAPSHOT(tomcat-shutdown) 
projectSucceeded BaseContrats:BaseContrats:1.0-SNAPSHOT 
sessionEnded 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 2:07.408s 
[INFO] Finished at: Mon Feb 25 09:32:08 CET 2013 
[INFO] Final Memory: 13M/51M 
[INFO] ------------------------------------------------------------------------ 
Projects to build: [MavenProject: BaseContrats:BaseContrats:1.0-SNAPSHOT @ C:\jenkins_home\workspace\Base Contrats EXT JS MAVEN\pom.xml] 
[JENKINS] Archiving C:\jenkins_home\workspace\Base Contrats EXT JS MAVEN\pom.xml to C:\jenkins_home\jobs\Base Contrats EXT JS MAVEN\modules\BaseContrats$BaseContrats\builds\2013-02-25_09-29-58\archive\BaseContrats\BaseContrats\1.0-SNAPSHOT\BaseContrats-1.0-SNAPSHOT.pom 
[JENKINS] Archiving C:\jenkins_home\workspace\Base Contrats EXT JS MAVEN\target\ConventionsJuridiques.war to C:\jenkins_home\jobs\Base Contrats EXT JS MAVEN\modules\BaseContrats$BaseContrats\builds\2013-02-25_09-29-58\archive\BaseContrats\BaseContrats\1.0-SNAPSHOT\BaseContrats-1.0-SNAPSHOT.war 
channel stopped 
Finished: SUCCESS 

回答

1

你可以看到Maven完成了成功。這將使詹金斯也取得成功。

爲了將構建標記爲不穩定,您需要一個構建後操作來分析測試結果並將構建標記爲失敗或不穩定。我建議您搜索Jenkins發佈構建操作的更多細節,以處理測試結果並根據需要標記構建。

希望這會有所幫助。

0

您應該在您的構建中添加一個步驟:「發佈Junit報告」 您將顯示所有測試結果的圖形,但如果測試失敗,它也會設置正確的構建結果。

+0

在我的Jenkins Post-Build Choice列表中不存在選擇「Publish Junit Report」。 – Clem 2013-02-25 12:55:31

2

根據the documentation

故障保護:驗證驗證應用程序的集成測試通過。

您需要將目標添加到Maven的故障保護,插件運行:

<goals> 
    <goal>integration-test</goal> 
    <goal>verify</goal> 
</goals> 

這將使詹金斯解釋測試結果並標記生成不穩定。

0

在後構建操作下,Publish JUnit測試結果報告更改要搜索的報告XML。

這個假設是使用標準surefire和故障安全插件輸出目錄。

enter image description here

變化

enter image description here

0

故障安全插件的目標「集成測試」並不標誌着建設成爲錯誤時,測試失敗。

您必須添加目標「驗證」才能在插件執行中的「集成測試」之後運行。這將查找錯誤或失敗並將構建標記爲「錯誤」。然後Jenkins會看到Maven沒有成功。