代码覆盖率-clover- 介绍

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yanmingming1989/article/details/8557963
学习地址:
http://wiki.hudson-ci.org/display/HUDSON/Clover+Plugin
Hudson 上 可选择的代码覆盖率插件有: 
1.   Clover Plugin — 该插件是在Hudson中集成 Clover code coverage reports(代码覆盖测试分析工具)。
2.   Emma Plugin — 该插件在Hudson中集成EMMA code coverage reports (检测和报告 JAVA 代码覆盖率的开源工具)。Hudson will generate the trend report of coverage.
分析: Clover Plugin 强调重点:测试覆盖率的分析工具, Emma Plugin 强调重点:分析代码覆盖率的趋势。
比较Emma与Clover
链接:http://www.taobaotest.com/blogs/qa?bid=6425
使用方法:http://www.taobaotest.com/blogs/qa?bid=3820
注意事项:
 必须使用   free-style software project  构建工程;
如何配置一个能够进行代码覆盖率统计分析的项目?
1. POM中配置(使用此版本的插件,不需要licence,但是只能运行在linux下的机器上):
<build>
        <plugins>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-clover2-plugin</artifactId>
                <version>1.0.0.nl-SNAPSHOT</version>
                <configuration>
                    <contextFilters>catch,static</contextFilters>
                    <includes>
                        <include>*.java</include>
                    </includes>
                    <includesTestSourceRoots>false</includesTestSourceRoots>
                    <generateHistorical>true</generateHistorical>
                    <encoding>GBK</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

问题:如果按照以上操作没有正确生成覆盖率文件,初步判断是 jar包中的lisence没有生效。
window 系统下,当官网上注册生成自己的证书,不过只能用30天,主POM中配置:
                 <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-clover2-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <includesTestSourceRoots>false</includesTestSourceRoots>
                    <generateHistorical>true</generateHistorical>
                    <encoding>GBK</encoding>
                    <licenseLocation>D:/clover.license</licenseLocation>
                </configuration>
            </plugin>
带有单元测试集的子POM配置:(跳过开发的单元测试集,我们自己的qatest就不需要添加这些代码了)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>   
        <version>2.4.2</version>   
        <configuration>   
          <skipTests>true</skipTests>   
        </configuration>   
</plugin>   

2,构建:
如果我们使用 

在goals 中输入: 

clover2:setup test clover2:aggregate clover2:clover -Dmaven.test.failure.ignore
备注:
如果我们队 checkout下来的代码不作处理,那么运行上面的命令就会直接执行所有module下的单元测试集,如果开发代码中的单元测试出现bug,那么会导致整个项目的运行失败,如何跳过开发的单元测试呢 ?
思考的方法一:删除开发代码下的test文件夹;证明是行不通的,因为我们每次运行代码前都会去 update 代码;
思考的方法二:命令中test后面添加-lp 指定只运行特定的模块,但是如果采用这个策略的话,只会在这顶的特定模块中打桩(clover),所以这种方法没法统计到开发的代码覆盖率(因为开发的代码没有被打桩)。
思考的方法二:在又单元测试的子module中,对POM文件做修改,在 <build> 添加代码:
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId>   
        <version>2.4.2</version>   
        <configuration>   
          <skipTests>true</skipTests>   
        </configuration>   
</plugin>   
意思就是  跳过本module下的单元测试。
注意:修改开发代码中的POM,只能在我们运行的hudson机器的job中去修改,切记别提交开发代码。

3. 构建后操作: 

选择

Publish Clover Coverage Report 
Clover report directory: target/site/clover
Clover report file name: clover.xml


4.设置运行触发时间:
 schedule setting for build periodically in hudson
Schedule的配置规则是有5个空格隔开的字符组成,从左到右分别代表:分 时 天 月 年。*代表所有,
                 0 12,20 * * * 表示在任何年任何月的任何天的12和20点的0分 进行构建!

猜你喜欢

转载自blog.csdn.net/yanmingming1989/article/details/8557963
今日推荐