希望我发布了有关此构建文件的所有必要详细信息。覆盖任务运行良好,所有测试用例都运行。
Jacoco.exec 也已生成,但报告任务失败 stating Unable to read execution data file C:/path/to/file/jacoco.exec
。
无法弄清楚我做错了什么。任何补充或替代方式?
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="${JACOCO.HOME}/lib/jacocoant.jar"/>
</taskdef>
<target name="runtest" depends="compile">
<jacoco:coverage destfile="${testdest}/jacoco.exec" xmlns:jacoco="antlib:org.jacoco.ant" exclclassloader="sun.reflect.DelegatingClassLoader:javassist.Loader" >
<junit haltonfailure="yes" fork="true" forkmode="once" printsummary="on">
<classpath refid="project.classpath" />
<classpath location="${testdest}" />
<formatter type="xml"/>
<batchtest fork="yes">
<fileset dir="${testdest}" />
</batchtest>
</junit>
</jacoco:coverage>
<jacoco:report xmlns:jacoco="antlib:org.jacoco.ant">
<executiondata>
<file file="${testdest}/jacoco.exec" />
</executiondata>
<structure name="Jacoco">
<classfiles>
<fileset dir="${dest}" />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src}" />
</sourcefiles>
</structure>
<html destdir="${testsrc}/report" />
</jacoco:report>
最佳答案
上述代码完美运行。出了什么问题,我试图多次运行构建文件,因为现有的 jacoco.exec 已损坏(我认为是由于 Junit 测试失败)并且它没有被执行。我删除了 jacoco.exec 文件并再次运行该文件,生成了完美执行的新 jacoco.exec 文件。
关于java - 使用 Ant 的 Jacoco 覆盖和报告任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34101314/