maven中实现代码单元测试覆盖率统计
来源:互联网 发布:淘宝买的官换机坏了 编辑:程序博客网 时间:2024/05/22 00:12
1.首先需要对统计模块的POM.XML增加如下字段:
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>cobertura-maven-plugin</artifactId>
- <version>2.6</version>
- <configuration>
- <formats>
- <format>html</format>
- <format>xml</format>
- </formats>
- </configuration>
- </plugin>
- </plugins>
- </reporting>
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>cobertura-maven-plugin</artifactId>
- <version>2.6</version>
- </plugin>
- </plugins>
- </reporting>
区别:在reporting节点中加入则在mvn site中执行,如果在build节点中加入,则在build的时候自动运行检查。
注意:如果是多模块的maven项目,需要在每个想统计模块的pom.xml中进行配置,这样会将各模块的报告进行汇集。
2.执行下面的cobertura命令
- mvn cobertura:help 查看cobertura插件的帮助
- mvn cobertura:clean 清空cobertura插件运行结果
- mvn cobertura:check 运行cobertura的检查任务
- mvn cobertura:cobertura 运行cobertura的检查任务并生成报表,报表生成在target/site/cobertura目录下
- cobertura:dump-datafile Cobertura Datafile Dump Mojo
- mvn cobertura:instrument Instrument the compiled classes
另,有的项目一些借口定义,常量定义和异常定义这些是不需要单元测试的,还有一些不重要的,我们可以进行过滤
按类的类别进行过滤
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<ignores>
<!--经过修改的 cobertura, 支持方法级别的过滤 -->
<ignore>*main*</ignore>
<!--以上修改指的是过滤项目中所有类中的方法名中含有 main 的方法 -->
</ignores>
<IgnoreTrival>true</IgnoreTrival>
</configuration>
</plugin>
或对路径过滤:
<configuration>
<instrumentation>
<excludes>
<!--此处用于指定哪些类会从单元测试的统计范围中被剔除 -->
<exclude>exs/res/process/egencia/Mock*.class</exclude>
<exclude>exs/res/process/test/**/*Test.class</exclude> </excludes>
</instrumentation>
</configuration>
<executions>
<execution>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
0 0
- maven中实现代码单元测试覆盖率统计
- 使用MAVEN+Jacoco统计单元测试的代码覆盖率
- 统计 Android 单元测试代码覆盖率
- 结合junit + ant + emma实现Android项目单元测试代码覆盖率统计
- 使用cobertura-maven-plugin做单元测试覆盖率统计
- JUNIT单元测试时统计代码的覆盖率工具eclemma安装
- maven工程加入jacoco检测单元测试代码覆盖率
- 单元测试代码覆盖率浅谈
- 单元测试代码覆盖率浅谈
- 单元测试代码覆盖率浅谈
- 单元测试与代码覆盖率
- 单元测试代码覆盖率浅谈
- Eclipse - UT - Eclipse 中单元测试覆盖率统计工具
- 使用Cobertura统计单元测试覆盖率
- 使用Cobertura统计单元测试覆盖率
- ios 单元测试(XCTestCase)覆盖率统计
- java测试中单元测试中Junit、mock和代码覆盖率
- python 代码覆盖率统计
- VO PO DTO DO 集中概念的理解
- MySQL 存储过程参数有三种类型:in、out、inout。它们各有什么作用和特点呢?
- 附近地点搜索初探
- 浅谈ARM架构(1)
- 此网站某个加载项运行失败。请检查“Internet”选项中的
- maven中实现代码单元测试覆盖率统计
- [Leetcode]Permutations && Permutations II
- android NDK开发及调用标准linux动态库.so文件
- Looper、Message和Handler的关系
- VMware View(四)——添加并配置vCenter Server
- PHP,Mysql-根据一个给定经纬度的点,进行附近地点查询–合理利用算法,效率提高2125倍
- 南宁丰脸颊哪里好
- sublime配置全攻略
- axure 7.0 注册码