我第一次尝试一些代码覆盖率分析,我正在使用ANT获得cobertura。我的问题可能很愚蠢,但我想在这里问一下。我的ANT脚本中包含以下内容。在阅读cobertura时,下一步是工具。什么是代码覆盖率插装?
<target name="cobertura" depends="checkstyle">
<property name="cobertura.dir" location="C:\\Softwares- packages\\Corbetura\\cobertura-1.9.4.1" />
<path id ="cobertura.classpath">
<fileset dir="${cobertura.dir}">
<include name="cobertura.jar"/>
<include name="lib/**/*.jar"/>
</fileset>
</path>
<taskdef resource="tasks.properties" classpathref="cobertura.classpath"/>
</target>发布于 2011-11-20 11:52:58
cobertura修改您的类文件,以便它可以计算覆盖率。我通常会“检测”用于执行测试的jar文件的副本,并将尚未检测的副本用作我的构建工件。
以下是我第一次通过ant设置cobertura时使用的构建文件:
cobertura-instrument目标插入我的代码,并将插入的类写入到一个单独的目录中,如您所说。
junit目标编译测试,然后检测测试,然后运行测试,然后生成报告。这些步骤都是通过声明junit one的依赖目标来完成的。
<path id="cobertura.classpath">
<fileset dir="${cobertura.dir}">
<include name="cobertura.jar" />
<include name="lib/**/*.jar" />
</fileset>
</path>
<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
<!-- Delete an existing coburtura datafile -->
<delete file="${cobertura.datafile}"/>
<antcall target="cobertura.clean"/>
<!-- Instrument the code with cobertura to test for coverage -->
<cobertura-instrument todir="${cobertura.instrumented.classes}" datafile="${cobertura.datafile}">
<fileset dir="${build.dir}/classes/">
<include name="**/*.class"/>
</fileset>
</cobertura-instrument>
<fileset dir="${src.dir}">
<include name="**/*.java" />
</fileset>
<fileset dir="${tests.src.dir}">
<include name="**/*.java" />
</fileset>发布于 2011-11-20 11:52:41
我相信你正在寻找"cobertura-instrument“任务。请参阅here
https://stackoverflow.com/questions/8199274
复制相似问题