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
  a)Sonar需要数据库的支持,其本身自带Derby同时支持MySQL5.x,
Oracle 10g XE,Postgresql和MS SqlServer 2005,推荐使用
MySQL。
  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文件中查看所有测试结果信息。