Ant를 사용하여 Emma 코드 적용 보고서를 어떻게 생성합니까?
-
09-06-2019 - |
문제
Ant 작업을 생성하도록 설정하는 방법은 무엇입니까? 엠마 코드 적용 범위 보고서?
해결책
소스 및 계측된 디렉터리가 어디에 있는지에 대한 질문에 대답하려면(표준 디렉터리 구조가 무엇이든 전환 가능):
<property file="build.properties" />
<property name="source" location="src/main/java" />
<property name="test.source" location="src/test/java" />
<property name="target.dir" location="target" />
<property name="target" location="${target.dir}/classes" />
<property name="test.target" location="${target.dir}/test-classes" />
<property name="instr.target" location="${target.dir}/instr-classes" />
클래스 경로:
<path id="compile.classpath">
<fileset dir="lib/main">
<include name="*.jar" />
</fileset>
</path>
<path id="test.compile.classpath">
<path refid="compile.classpath" />
<pathelement location="lib/test/junit-4.6.jar" />
<pathelement location="${target}" />
</path>
<path id="junit.classpath">
<path refid="test.compile.classpath" />
<pathelement location="${test.target}" />
</path>
먼저 Ant가 Emma 라이브러리를 찾을 수 있는 위치를 설정해야 합니다.
<path id="emma.lib" >
<pathelement location="${emma.dir}/emma.jar" />
<pathelement location="${emma.dir}/emma_ant.jar" />
</path>
그런 다음 작업을 가져옵니다.
<taskdef resource="emma_ant.properties" classpathref="emma.lib" />
그런 다음 코드를 계측합니다.
<target name="coverage.instrumentation">
<mkdir dir="${instr.target}"/>
<mkdir dir="${coverage}"/>
<emma>
<instr instrpath="${target}" destdir="${instr.target}" metadatafile="${coverage}/metadata.emma" mode="copy">
<filter excludes="*Test*"/>
</instr>
</emma>
<!-- Update the that will run the instrumented code -->
<path id="test.classpath">
<pathelement location="${instr.target}"/>
<path refid="junit.classpath"/>
<pathelement location="${emma.dir}/emma.jar"/>
</path>
</target>
그런 다음 다음과 같은 적절한 VM 인수를 사용하여 대상을 실행합니다.
<jvmarg value="-Demma.coverage.out.file=${coverage}/coverage.emma" />
<jvmarg value="-Demma.coverage.out.merge=true" />
마지막으로 보고서를 생성하십시오.
<target name="coverage.report" depends="coverage.instrumentation">
<emma>
<report sourcepath="${source}" depth="method">
<fileset dir="${coverage}" >
<include name="*.emma" />
</fileset>
<html outfile="${coverage}/coverage.html" />
</report>
</emma>
</target>
다른 팁
그만큼 사용자 가이드에는 빌드 스크립트를 설정하는 방법에 대한 좋은 예가 있습니다. 계측된 코드를 실행에서 분리할 뿐만 아니라 모두 동일한 코드에 포함됩니다. <target>
일련의 다른 대상을 실행할 필요 없이 대신 다음과 같은 작업을 수행할 수 있습니다. ant emma tests
(만약에 ant tests
예를 들어, 일반적으로 단위 테스트를 실행하는 방법이었습니다.)
그 예는 다음과 같습니다.
<target name="emma" description="turns on EMMA instrumentation/reporting" >
<property name="emma.enabled" value="true" />
<!-- EMMA instr class output directory: -->
<property name="out.instr.dir" value="${basedir}/outinstr" />
<mkdir dir="${out.instr.dir}" />
</target>
<target name="run" depends="init, compile" description="runs the examples" >
<emma enabled="${emma.enabled}" >
<instr instrpathref="run.classpath"
destdir="${out.instr.dir}"
metadatafile="${coverage.dir}/metadata.emma"
merge="true"
/>
</emma>
<!-- note from matt b: you could just as easily have a <junit> task here! -->
<java classname="Main" fork="true" >
<classpath>
<pathelement location="${out.instr.dir}" />
<path refid="run.classpath" />
<path refid="emma.lib" />
</classpath>
<jvmarg value="-Demma.coverage.out.file=${coverage.dir}/coverage.emma" />
<jvmarg value="-Demma.coverage.out.merge=true" />
</java>
<emma enabled="${emma.enabled}" >
<report sourcepath="${src.dir}" >
<fileset dir="${coverage.dir}" >
<include name="*.emma" />
</fileset>
<txt outfile="${coverage.dir}/coverage.txt" />
<html outfile="${coverage.dir}/coverage.html" />
</report>
</emma>
</target>
Emma 2.1에는 런타임 적용 범위 정보(.ec 파일)를 얻는 또 다른 방법이 도입되었습니다.계측된 응용 프로그램이 실행되는 컴퓨터의 지정된 포트에서 데이터를 원격으로 요청할 수 있습니다.따라서 VM을 중지할 필요가 없습니다.
런타임 적용 범위 데이터가 포함된 파일을 얻으려면 테스트 실행과 적용 범위 보고서 생성 사이에 Ant 스크립트에 다음 스니펫을 삽입해야 합니다.
<emma>
<ctl connect="${emma.rt.host}:${emma.rt.port}" >
<command name="coverage.get" args="${emma.ec.file}" />
<command name="coverage.reset" />
</ctl>
</emma>
다른 단계는 Emma 2.0과 유사합니다.그들은 완벽하게 설명되어 있습니다 이전 게시물
Emma 2.1 기능에 대한 추가 정보: http://sourceforge.net/project/shownotes.php?group_id=108932&release_id=336859