ant中<emma>的使用

上一篇 / 下一篇  2009-03-12 17:56:35 / 个人分类:Ant

参考文章

http://www.miiceic.org.cn/07/0706/070603/200701291038429.asp
http://dohkoos.name/ant-series-emma-measuring-test-coverage-with-the-question-of-when.html

emma下载:http://emma.sourceforge.net/

安装emma:把emma.jar、emma_ant.jar两个包放到ANT_HOME\lib下

emma-2.0.5312.zip(676 KB)


使用到的代码段如下:

 <path id="classpath">
  <pathelement location="${coverage.instr}"/>  //这句要在classpath的第一行
  <pathelement location="${classes}" />
 </path>


 <path id="emma.lib" >
  <pathelement location="${ant_lib}\emma.jar" />
  <pathelement location="${ant_lib}\emma_ant.jar" />
 </path>

//在ANT脚本中加入EMMA这个TASK
 <taskdef resource="emma_ant.properties" classpathref="emma.lib" />

 <!--coverage instrument-->
 <target name="coverage.instrument" depends="compile">
  <emma enabled="yes">
   <instr instrpath="${classes}" destdir="${coverage.instr}" metadatafile="${coverage.report.dir}
\metadata.emma" merge="true" >
   </instr>
  </emma>
 </target>

//下面sysproperty与jvmarg的功能相同,两种方式都可以使用
 <!-- run junit test-->
 <target name="test" depends="coverage.instrument">
  <junit printsummary="on" haltonfailure="false" fork="true" failureproperty="tests.failed" showoutput="true">
   <!--<sysproperty key="emma.coverage.out.file" value="${coverage.report.dir}\coverage.emma" />-->
   <classpath refid="classpath" />
   <jvmarg value="-Demma.coverage.out.file=${coverage.report.dir}\coverage.emma" />
   <jvmarg value="-Demma.coverage.out.merge=true" />
 
   <formatter type="xml" />
   <batchtest todir="${junit.report.dir}" >
    <fileset dir="${classes}">
     <include name="**/TestCore.class"/>
    </fileset>
   </batchtest>
  </junit>
 </target>

//生成报告,并以metrics为失败或成功的指标
 <!--coverage report-->
 <target name="coverageReport" depends="test">
  <emma enabled="yes">
   <report sourcepath="${src.java}" sort="+block,+name,+method,+class" 
metrics="method:70,block:80,line:80,class:100">
    <fileset dir="${coverage.report.dir}">
     <include name="*.emma"/>
    </fileset>
    <html utfile="${coverage.report.dir}\coverage.html" depth="method" />
   </report>
  </emma>
 </target>

 

 


TAG:

 

评分:0

我来说两句

Open Toolbar