1. MAVEN + SVN + HUDSON + SONAR集成測試環境搭建、
1. MAVEN + SVN + HUDSON + SONAR集成測試環境搭建、
1.1 軟件準備
Hudson、Jenkins、Sonar
1.2 軟件安裝
說明:本例均使用將應用程序部署至web容器下,Hudson和Sonar有其他部署啟動方式,如有需要請自行使用,本文不做贅述。
1.2.1 安裝hudson
1)將下載到的hudson.war文件部署至web容器中,啟動web容器。
2)訪問地址http://localhost:8080/hudson,顯示如下:
(8080是容器默認端口,hudson是項目名稱)
1.2.2 安裝sonar
說明:以下內容是快速安裝的示例。
1)解壓sonar.zip,進入war文件夾下,運行build-war文件,會生成sonar.war文件
2)將sonar.war文件部署至web容器下,啟動容器
3)訪問地址http://localhost:8080/sonar/,顯示如下:
4)(8080是容器默認端口,sonar是項目名稱)
1.3 軟件配置
1.3.1 配置sonar
1)創建數據庫
b)創建數據庫:MySQL中創建用戶sonar,同時創建數據庫sonar,未用戶sonar賦予權限。
說明:表和索引活在sonar激活后自動創建。
2)配置數據庫,編輯conf/sonar.properties
sonar.jdbc.username: sonar sonar.jdbc.password: sonar sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true sonar.jdbc.driverClassName:com.mysql.jdbc.Driver |
說明:更改數據庫配置,請注意extensions/jdbc-driver/mysql/目錄下是否有對應的驅動
1.3.2 配置hudson
請保證Hudson已經安裝以下插件:
進入Manage Hudson ->Config System進行配置,顯示如下:
1)系統信息配置:
Home directory:hudson目錄
System Message:hudson系統說明信息
# of executors:同時可執行最大數
Quiet period:構建工程之前的等候時間,單位是s,此項較重要可以保證構建工程時項目的完整性
SCM checkout retry count:檢出失敗重試次數2)安全信息配置:
3)JDK配置:
如果系統配置已為JDK配置了環境變量,則此處可以不做設置
4)Maven配置:
Name:為你的maven指定名稱
MAVEN_HOME:指定maven安裝路徑
5)SVN配置:
Exclusion revprop name:指定項目SVN路徑
1.4 環境集成
1.4.1 Maven與Sonar集成
編輯$MAVEN_HOME/conf或者~/.m2下的setting.xml文件,添加如下內容:
<!--sonar --> <profile> <id>sonar</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <!-- mysql--> <sonar.jdbc.url> jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true </sonar.jdbc.url> <sonar.jdbc.driver> com.mysql.jdbc.Driver</sonar.jdbc.driver> <sonar.jdbc.username>sonar</sonar.jdbc.username> <sonar.jdbc.password>sonar</sonar.jdbc.password> <!--remote host--> <sonar.host.url>http://localhost:8080/sonar</sonar.host.url> </properties> </profile> |
說明: 因為sonar是通過Maven2插件來分析源代碼并把結果注入到數據庫的,所以必須在Maven的配置里設置數據庫的屬性。
1.4.2 hudson與sonar集成
1)安裝sonar插件
2)配置Sonar參數(服務地址和數據庫地址)
1.5 創建和配置job
1.5.1 創建JOB,點擊New Job,顯示如下:
1.5.2 點擊OK,顯示如下:
1)工程概要配置:
2)工程高級配置:
3)源碼管理:
高級配置:
4)構建
2.Eclipse中IDE環境下集成測試
說明:在IDE環境下集成測試非常方便,可以使用的組件有dashboard、cobertura、findbugs
2.1 Findbugs:根據既定規則檢查代碼bug
1)修改工程的pom.xml文件,添加findbugs-maven-plugin插件
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plugin</artifactId> <version>2.5.1</version> <configuration> <threshold>High</threshold> <effort>Default</effort> <findbugsXmlOutput>true</findbugsXmlOutput> <!-- findbugs xml輸出路徑--> <findbugsXmlOutputDirectory>target/site</findbugsXmlOutputDirectory> </configuration> </plugin> |
2)輸入命令:
mvn findbugs:findbugs
3)結果會生成在target/目錄下findbugsXml.xml文件中
2.2 Cobertura:測試覆蓋率插件
1)修改工程的pom.xml文件,添加cobertura-maven-plugin插件
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.5.1</version> </plugin> |
2)輸入命令:
mvn cobertura:cobertura
3)結果生成在target/site/cobertura目錄下
2.3 Dashboard:圖表顯示測試結果
1)修改工程的pom.xml文件,添加dashboard-maven-plugin插件
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>dashboard-maven-plugin</artifactId> <version>1.0.0-beta-1</version> </plugin> |
2)輸入命令:
mvn site mvn dashboard:dashboard |
3)在項目targe/site目錄下打開dashboard頁面查看結果
如果安裝了dashboard插件,可以在dashaboard文件中查看所有測試結果信息。
posted on 2014-03-12 10:48 順其自然EVO 閱讀(1362) 評論(0) 編輯 收藏 所屬分類: 持續集成 、maven