qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請(qǐng)?jiān)L問 http://qaseven.github.io/

          1. MAVEN + SVN + HUDSON + SONAR集成測(cè)試環(huán)境搭建、

          1. MAVEN + SVN + HUDSON + SONAR集成測(cè)試環(huán)境搭建、
            1.1 軟件準(zhǔn)備
            Hudson、Jenkins、Sonar
            1.2 軟件安裝
            說明:本例均使用將應(yīng)用程序部署至web容器下,Hudson和Sonar有其他部署啟動(dòng)方式,如有需要請(qǐng)自行使用,本文不做贅述。
            1.2.1 安裝hudson
            1)將下載到的hudson.war文件部署至web容器中,啟動(dòng)web容器。
            2)訪問地址http://localhost:8080/hudson,顯示如下:
            (8080是容器默認(rèn)端口,hudson是項(xiàng)目名稱)
            1.2.2 安裝sonar
            說明:以下內(nèi)容是快速安裝的示例。
            1)解壓sonar.zip,進(jìn)入war文件夾下,運(yùn)行build-war文件,會(huì)生成sonar.war文件
            2)將sonar.war文件部署至web容器下,啟動(dòng)容器
            3)訪問地址http://localhost:8080/sonar/,顯示如下:
            4)(8080是容器默認(rèn)端口,sonar是項(xiàng)目名稱)
            1.3 軟件配置
            1.3.1 配置sonar
            1)創(chuàng)建數(shù)據(jù)庫(kù)
            a)Sonar需要數(shù)據(jù)庫(kù)的支持,其本身自帶Derby同時(shí)支持MySQL5.x,Oracle 10g XE,Postgresql和MS SqlServer 2005,推薦使用MySQL
            b)創(chuàng)建數(shù)據(jù)庫(kù):MySQL中創(chuàng)建用戶sonar,同時(shí)創(chuàng)建數(shù)據(jù)庫(kù)sonar,未用戶sonar賦予權(quán)限。
            說明:表和索引活在sonar激活后自動(dòng)創(chuàng)建。
            2)配置數(shù)據(jù)庫(kù),編輯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
            說明:更改數(shù)據(jù)庫(kù)配置,請(qǐng)注意extensions/jdbc-driver/mysql/目錄下是否有對(duì)應(yīng)的驅(qū)動(dòng)
            1.3.2 配置hudson
            請(qǐng)保證Hudson已經(jīng)安裝以下插件:
            進(jìn)入Manage Hudson ->Config System進(jìn)行配置,顯示如下:
            1)系統(tǒng)信息配置:
            Home directory:hudson目錄
            System Message:hudson系統(tǒng)說明信息
            # of executors:同時(shí)可執(zhí)行最大數(shù)
            Quiet period:構(gòu)建工程之前的等候時(shí)間,單位是s,此項(xiàng)較重要可以保證構(gòu)建工程時(shí)項(xiàng)目的完整性
            SCM checkout retry count:檢出失敗重試次數(shù)2)安全信息配置:
            3)JDK配置:
            如果系統(tǒng)配置已為JDK配置了環(huán)境變量,則此處可以不做設(shè)置
            4)Maven配置:
            Name:為你的maven指定名稱
            MAVEN_HOME:指定maven安裝路徑
            5)SVN配置:
            Exclusion revprop name:指定項(xiàng)目SVN路徑
            1.4 環(huán)境集成
            1.4.1 Maven與Sonar集成
            編輯$MAVEN_HOME/conf或者~/.m2下的setting.xml文件,添加如下內(nèi)容:
          <!--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>
            說明: 因?yàn)閟onar是通過Maven2插件來分析源代碼并把結(jié)果注入到數(shù)據(jù)庫(kù)的,所以必須在Maven的配置里設(shè)置數(shù)據(jù)庫(kù)的屬性。
            1.4.2 hudson與sonar集成
            1)安裝sonar插件
            2)配置Sonar參數(shù)(服務(wù)地址和數(shù)據(jù)庫(kù)地址)
            1.5 創(chuàng)建和配置job
            1.5.1 創(chuàng)建JOB,點(diǎn)擊New Job,顯示如下:
            1.5.2 點(diǎn)擊OK,顯示如下:
            1)工程概要配置:
            2)工程高級(jí)配置:
            3)源碼管理:
            高級(jí)配置:
            4)構(gòu)建
            2.Eclipse中IDE環(huán)境下集成測(cè)試
            說明:在IDE環(huán)境下集成測(cè)試非常方便,可以使用的組件有dashboard、cobertura、findbugs
            2.1   Findbugs:根據(jù)既定規(guī)則檢查代碼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)結(jié)果會(huì)生成在target/目錄下findbugsXml.xml文件中
            2.2 Cobertura:測(cè)試覆蓋率插件
            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)結(jié)果生成在target/site/cobertura目錄下
            2.3   Dashboard:圖表顯示測(cè)試結(jié)果
            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)在項(xiàng)目targe/site目錄下打開dashboard頁(yè)面查看結(jié)果
            如果安裝了dashboard插件,可以在dashaboard文件中查看所有測(cè)試結(jié)果信息。

          posted on 2014-03-12 10:48 順其自然EVO 閱讀(1362) 評(píng)論(0)  編輯  收藏 所屬分類: 持續(xù)集成maven

          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 平定县| 军事| 虞城县| 大理市| 雷山县| 祁东县| 庆阳市| 浪卡子县| 防城港市| 沙雅县| 兴化市| 仙游县| 达尔| 正定县| 蚌埠市| 新安县| 荆门市| 扬州市| 图们市| 徐汇区| 永年县| 丹东市| 循化| 神池县| 积石山| 博兴县| 安吉县| 普定县| 封开县| 广平县| 东安县| 沁源县| 西平县| 商南县| 望奎县| 彭山县| 乌兰察布市| 定襄县| 河曲县| 安吉县| 克什克腾旗|