Cobertura是一个基于jcoverage的免费Java工具,它能够显示哪一部分代码被你的测试所覆盖,并可生成HTML或XML报告.
cobertura 的大概基本工作思路:
1.对已经编译好的class 文件添加标记
2. 对添加好标记的代码进行单元测试
3. 输出覆盖率统计报告
在ant 中使用cobertura 的基本步骤:
1. 编译代码
2. 定义cobertura 的ant task
3. 用nstrument 命令为编译好的代码添加标记
4. 用junit 命令对添加好标记的代码进行单元测试
5. 用cobertura-report 命令输出报告
编译代码:
<target name="compile">
<ant antfile="build.xml" inheritAll="false" target="compile"/>
</target>
在 build.xml 文件中添加一个任务定义:
<path id="cobertura.classpath">
<fileset dir="${lib.dir}">
<include name="cobertura/*.jar"/>
</fileset>
<pathelement location="${cobertura.instrumented.classes.dir}"/>
</path>
<taskdef classpathref="cobertura.classpath" resource="tasks.properties"/>
添加一个instrument
任务,该任务将在已经编译好的类文件中添加标记。todir
属性指定将测量类放到什么地方。fileset
子元素指定测量哪些 .class文件:
<target name="instrument" depends="compile">
<cobertura-instrument todir="${cobertura.instrumented.classes.dir}">
<fileset dir="${build.src.dir}">
<include name="**/*.class"/>
<exclude name="**/web/**/*.class"/>
<exclude name="**/constant/*.class"/>
<exclude name="**/*Test.class"/>
</fileset>
</cobertura-instrument>
</target>
可以排除一些不需要检查的class文件。
运行测试:
<target name="cover-test" depends="instrument">
<mkdir dir="${cobertura.report.dir}"/>
<junit fork="true" failureproperty="unit.tests.failed" printsummary="true" showoutput="yes">
<classpath>
<!--
Note the classpath order: instrumented classes are before the
original (uninstrumented) classes. This is important.
-->
<path refid="cobertura.classpath"/>
<path refid="test.classpath"/>
</classpath>
<formatter type="xml"/>
<batchtest todir="${cobertura.report.dir}">
<fileset dir="${build.unittest.dir}">
<include name="**/*Test.class"/>
</fileset>
<fileset dir="${build.functionaltest.dir}">
<include name="**/*Test.class"/>
</fileset>
<fileset dir="${build.integrationtest.dir}">
<include name="**/*Test.class"/>
</fileset>
</batchtest>
</junit>
</target>
最后,生成测试测量报告:
<target name="coverage-report" depends="cover-test">
<cobertura-report format="html" destdir="${cobertura.report.dir}" srcdir="${src.dir}"/>
</target>
生成的报告形式大概如下:
- 描述: 测量效果图
- 大小: 574.5 KB
- 描述: 测量效果图
- 大小: 311.4 KB
分享到:
相关推荐
NULL 博文链接:https://mwhgjava.iteye.com/blog/1297276
NULL 博文链接:https://terrencexu.iteye.com/blog/718834
Cobertura代码覆盖率测试工具介绍文档,Cobertura代码覆盖率测试工具介绍
Cobertura 是一种代码覆盖测试工具,它通过检测基本的代码,并观察在测试包运行时执行了哪些代码和没有执行哪些代码,来测量测试覆盖率。
Cobertura是一种开源工具,它通过检测基本的代码,并观察在测试包运行时执行了哪些代码和没有执行哪些代码,来测量测试覆盖率。除了找出未测试到的代码并发现bug外,Cobertura还可以通过标记无用的、执行不到的代码...
cobertura代码覆盖率工具,有工具包,并且付上一份自己给项目组写的手册一份。
cobertura和weblogic整合使用-代码覆盖率测试 里面详细步骤和使用说明,并附加xml文件,不懂的可以QQ我,147806015,
Cobertura是一个测试案例覆盖率统计工具,此资源下载后,解压,配置上环境变量即可使用
代码测试覆盖率工具,该工具与ant执行集成,快速简单有效的测试代码的覆盖率,内附测试用例
它也旨在通过pycobertura diff命令来防止代码覆盖率降低:任何更改的行都应进行测试,并且未覆盖的更改应清晰可见,而不会让遗留的未覆盖代码成为pycobertura diff因此开发人员可以仅专注于其更改。 特征: 显示...
cobertura测试代码
此包使用分析器生成 Cobertura 样式的 XML 覆盖率报告。 我们将此报告与 Hudson/Jenkins 结合使用来跟踪测试覆盖率。 下面的代码示例说明了如何使用代码。 有关详细信息,请参见 example.m。 %将源代码添加到路径...
JSCover 是一个易于使用的 JavaScript 代码覆盖率测量工具。它是流行的 JSCoverage工具的增强版本,增加了一些功能,包括分支覆盖率、 LCOV和用于 CI 集成的Cobertura XML报告、用于自动化测试的钩子和HTML 本地存储...
代码测试覆盖率工具包cobertura.jar
cobertura源代码,包括举例,JUnit的例子已经跑通,功能比较强大
Cobertura可用于分析Java代码的测试覆盖率。Cobertura根据没有被测试覆盖的代码生成基于HTML的报告。 Cobertura提供可用于插装、检查和测试代码的工具。通过监控可测试的代码,Cobertura允许你使用你选择的测试框架...
cobertura 单元测试覆盖率