使用Ant的Jacoco覆盖和报告任务

时间:2015-12-05 04:33:15

标签: java ant jacoco

希望我发布了有关此构建文件的所有必要详细信息。覆盖任务工作正常,所有测试用例都运行。

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>

1 个答案:

答案 0 :(得分:2)

以上陈述的代码完美无缺。出了什么问题,我试图运行构建文件太多次,因为现有的jacoco.exec已损坏(由于我认为Junit测试失败)并且它没有被执行。我删除了jacoco.exec文件并再次运行该文件,生成了新的jacoco.exec文件,该文件执行得非常完美。

相关问题