覆盖率工具-jacoco 集成进jenkins
2016-04-22 00:35
459 查看
Jacoco是一个开源的覆盖率工具。Jacoco可以嵌入到Ant 、Maven中,并提供了EclEmma Eclipse插件,也可以使用Java Agent技术监控Java程序。很多第三方的工具提供了对Jacoco的集成,如sonar、Jenkins、IDEA. Jacoco包含了多种尺度的覆盖率计数器,包含指令级(Instructions,C0 coverage),分支(Branches,C1 coverage)、圈复杂度(Cyclomatic Complexity)、行(Lines)、方法(non-abstract
methods)、类(classes)。
具体的maven配置如下,plugin的版本可以到nexus上搜下,现在nexus上最新的是0.7.2.201409121644:
jenkins->系统管理->管理插件 搜索Jenkins JaCoCo plugin 安装
可以配置覆盖率统计的class
Path to exec files:代码覆盖率统计文件位置;
Path to class directories:classes文件位置;
Path to source directories :源码文件位置;
下面是设置覆盖率百分比的提醒阈值。
太阳表示覆盖率高于设置阈值,覆盖率报告里会橙色提醒
乌云表示覆盖率低于设置阈值,覆盖率报告里会橙色提醒
本来想在现在的view上直接增加一列,按照官方的方法(https://wiki.jenkins-ci.org/display/JENKINS/Changing+the+Columns+of+a+View)设置无果
所以只能新建一个view
选取job,然后添加一列,如下图,保存即可。
执行job的构建后,会生成覆盖率报告
http://blog.csdn.net/kittyboy0001/article/details/18706067
http://www.petrikainulainen.net/programming/maven/creating-code-coverage-reports-for-unit-and-integration-tests-with-the-jacoco-maven-plugin/
关于几种覆盖率工具的比较 https://answers.atlassian.com/questions/9880767/clover-vs-cobertura-jacoco-and-other-code-coverage-tools
methods)、类(classes)。
jacoco-maven-plugin
具体的maven配置如下,plugin的版本可以到nexus上搜下,现在nexus上最新的是0.7.2.201409121644:<!-- jacoco plugin --> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.7.2.201409121644</version> <executions> <execution> <!-- 在maven的initialize阶段,将Jacoco的runtime agent作为VM的一个参数 传给被测程序,用于监控JVM中的调用。 --> <id>default-prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> <configuration> <destFile> ${project.build.directory}/coverage-reports/jacoco.exec </destFile> <propertyName>surefireArgLine</propertyName> </configuration> </execution> <!-- 在程序的verify阶段,执行report测试的程序。 文件的输入为perpare-agent阶段中设置或者默认的jacoco.exec. 参数 includes和excludes可用来选定report中过滤的类。 --> <execution> <id>default-report</id> <phase>test</phase> <goals> <goal>report</goal> </goals> <configuration> <dataFile>${project.build.directory}/coverage-reports/jacoco.exec</dataFile> <outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory> </configuration> </execution> </executions> </plugin>
jacoco集成进jenkins
1、安装jacoco插件
jenkins->系统管理->管理插件 搜索Jenkins JaCoCo plugin 安装
2、job中配置 post-build-action,生成覆盖率报告
可以配置覆盖率统计的class
Path to exec files:代码覆盖率统计文件位置;
Path to class directories:classes文件位置;
Path to source directories :源码文件位置;
下面是设置覆盖率百分比的提醒阈值。
太阳表示覆盖率高于设置阈值,覆盖率报告里会橙色提醒
乌云表示覆盖率低于设置阈值,覆盖率报告里会橙色提醒
3、在view里面显示覆盖率
本来想在现在的view上直接增加一列,按照官方的方法(https://wiki.jenkins-ci.org/display/JENKINS/Changing+the+Columns+of+a+View)设置无果
所以只能新建一个view
选取job,然后添加一列,如下图,保存即可。
4、查看覆盖率报告
执行job的构建后,会生成覆盖率报告
参考
http://blog.csdn.net/kittyboy0001/article/details/18706067http://www.petrikainulainen.net/programming/maven/creating-code-coverage-reports-for-unit-and-integration-tests-with-the-jacoco-maven-plugin/
关于几种覆盖率工具的比较 https://answers.atlassian.com/questions/9880767/clover-vs-cobertura-jacoco-and-other-code-coverage-tools
相关文章推荐
- 杭电2023 求平均成绩
- 【C++】static_cast, dynamic_cast, reinterpret_cast, const_cast区别比较
- 杭电1872稳定排序
- leetcode: Pascal's Triangle | Java最短代码实现
- mac上设置xampp服务器
- 基于spring test框架进行单元测试-框架介绍
- 关于<script/>
- 深入HTTP协议
- 2015-2016 下半学期 第六周 训练
- Java多线程——sleep(),wait(),notify(),notifyAll(),join()
- [改善Java代码]推荐使用枚举定义常量
- 个人工作总结4
- 换乐网redis应用分析
- hibernate的Many2One、Many2Many等的使用
- ucos中OSMemCreate()函数难点解析
- DbUnit实践:Spring Test Dbunit,H2数据库
- 数据库变慢问题定位方式
- Adobe CS2提供免费序列号,官网宣布Photoshop cs2免费
- MS SQL Server中数据表、视图、函数/方法、存储过程是否存在判断及创建
- CSS的盒子模型以及BFC