on-the-fly模式:使用emmarun-使用-g选项编程java源代码,javac -g -d out ,然后执行java emmarun -cp out 。本方法把instrumentation和执行过程合而为一。
offline 模式:分开instrumentation过程和执行过程-首先使用-g选项编译java源代码,javac -g -d out ;然后是 instrumentation,java emma instr -d outinstr -ip out,注意,经过instrumentation 的class目标目录是outinstr;最后是执行过程,java -cp outinstr;out ,注意,把经过instrumentation 的类路径放在前面,并在后面加上原来的类路径,因为instr命令没有处理properties文件和interface,这些都是执行过程需要的。
使用EMMA:Ant
设置instrumentation属性
<property name="coverage.dir" value="${basedir}/coverage" /> <property name="out.instr.dir" value="${basedir}/outinstr" /> <property name="emma.enabled" value="true" /> <property name="javac.debug" value="on" /> <!-- path element used by EMMA taskdef below: --> <path id="emma.lib" > <pathelement location="${libs}/emma.jar" /> <pathelement location="${libs}/emma_ant.jar" /> </path> |
在Ant脚本中加入EMMA task
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/