`
zhanshenny
  • 浏览: 259734 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

使用cobertura-maven-plugin做单元测试覆盖率统计

阅读更多
    cobertura-maven-plugin提供单元测试整体覆盖率以及分支覆盖率的统计工具,给编写单元测试的开发者提供一个参考,在pom.xml的配置如下:
                <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <formats>
                        <format>xml</format>
                    </formats>
                    <check>
<branchRate>0</branchRate>
<lineRate>0</lineRate>
<haltOnFailure>true</haltOnFailure>
<totalBranchRate>0</totalBranchRate>
<totalLineRate>0</totalLineRate>
<packageLineRate>0</packageLineRate>
<packageBranchRate>0</packageBranchRate>
<regexes>
  <regex>
<pattern>com.company.mode.services.*</pattern>
<branchRate>60</branchRate>
<lineRate>80</lineRate>
  </regex>
</regexes>
</check>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>clean</goal>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

    在项目目录下运行mvn cobertura:cobertura即可生成target目录下生成site\cobertura目录,里面存放了所有的单元测试报告,组织形式如javadoc.其中index.html对所有包的覆盖率做了统计

    cobertura-maven-plugin还提供了mvn cobertura:check命令来在verify阶段查看代码覆盖率是否达到预设要求,给项目管理者提供了一个检查代码覆盖率的工具。
      maven给管理者一套监控项目过程中代码质量的统计工具,也给开发者提供了衡量并改进代码测试的工具,提供了开发效率。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics