Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jacoco Coverage and Report Task with Ant

Tags:

java

ant

jacoco

Hopefully I am posted all the necessary details about this build file. Coverage task works fine and all the test cases runs.

Jacoco.exec is also generated but report task fails stating Unable to read execution data file C:/path/to/file/jacoco.exec.

Cant figure out what I am doing wrong. Any additions or alternative way ??

<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>

like image 688
zyas Avatar asked Sep 20 '25 01:09

zyas


1 Answers

Well above stated code works perfectly. What went wrong was, I tried to run the build file too many times due to this the existing jacoco.exec was corrupt(due to failed Junit test i think) and it was not being executed. I deleted the jacoco.exec file and ran the file again which generated new jacoco.exec file which executed perfectly.

like image 102
zyas Avatar answered Sep 22 '25 17:09

zyas