EclEmma
生成測試覆蓋度,並使用ant生成測試報告
1. Eclipse插件安裝:
- 官網安裝三種方式(注:嘗試第三種方式未生效,不知道爲啥,多是我Eclipse的問題)
2. Ant生成junit報告
<target name="junit" depends="clean,build-test">
<mkdir dir="${report.dir}" />
<junit printsummary="on" fork="false" showoutput="true">
<classpath refid="master-classpath" />
<formatter type="xml" />
<batchtest todir="${report.dir}">
<fileset dir="${build.dir}">
<include name="tests/Test*" />
</fileset>
</batchtest>
</junit>
<junitreport todir="${report.dir}">
<fileset dir="${report.dir}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${report.dir}" />
</junitreport>
</target>
- 這裏省略了兩個依賴:
clean
,build-test
,其中clean
清理生成的class文件,build-test是對要生成報告的類的編譯
master-classpath
運行須要的Jar包:這裏是junit4
report.dir
是報告生成目錄;build.dir
是編譯class的路徑
junit
任務包含兩步:junit運行測試(junit
),生成報告(junitreport
)
EclEmma生成測試覆蓋度
<target name="coverage">
<jacoco:coverage destfile="${basedir}/jacoco.exec">
<junit haltonfailure="false" fork="true" printsummary="true">
<classpath refid="master-classpath"/>
<formatter type="xml" />
<batchtest todir="${report.dir}" fork="true">
<fileset dir="${build.dir}">
<include name="tests/Test*" />
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
</target>
<target name="coverreport" depends="coverage">
<jacoco:report>
<executiondata>
<file file="${basedir}/jacoco.exec" />
</executiondata>
<structure name="unit test coverage rate report.">
<classfiles>
<fileset dir="${build.dir}">
<include name="tests/Test*" />
</fileset>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}">
<include name="tests/Test*" />
</fileset>
</sourcefiles>
</structure>
<html footer="footer" destdir="${report.dir.coverage}" />
<csv destfile="${report.dir.coverage}/coverage-report.csv" />
<xml destfile="${report.dir.coverage}/coverage-report.xml" />
</jacoco:report>
</target>
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath refid="jacoco-classpath"/>
</taskdef>
report.dir.coverage
是覆蓋率存放路徑