Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jacoco ant task - no jacoco.exec output

Tags:

java

ant

jacoco

I configured my Ant task as

<target name="test" depends="init">
    <jacoco:coverage destfile="target/jacoco.exec">
        <junit printsummary="yes" haltonfailure="yes" fork="yes" forkmode="once">
            <classpath refid="my_project.path"/>
            <formatter type="plain"/>
            <formatter type="xml"/>
            <batchtest fork="false" todir="target/test-reports">
                <fileset dir="test">
                    <include name="**/*Test.java"/>
                </fileset>
            </batchtest>
        </junit>
    </jacoco:coverage>
</target>

Which produces the expected junit result. However, the target/jacoco.exec is never created. I do not have any error during the ant test report task execution.

test: [jacoco:coverage] Enhancing junit with coverage

...

[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0,009 sec

report: [jacoco:report] Loading execution data file /home/usr/Workspaces/my_project/target/jacoco.exec

BUILD FAILED /home/usr/Workspaces/my_project/build.xml:73: Unable to read execution data file /home/usr/Workspaces/my_project/target/jacoco.exec

Total time: 14 seconds

Seems like I am missing something, unable to see what exactly.

like image 930
Olivier.Roger Avatar asked Apr 04 '13 09:04

Olivier.Roger


2 Answers

I found the cause. It is stupid but there was no logging to indicate the error:

batchtest fork="true" todir="target/test-reports"

The fork parameter was set to false in the batchtest. Setting it back to "true" produces the expected jacoco.exec.

like image 178
Olivier.Roger Avatar answered Sep 21 '22 17:09

Olivier.Roger


Running the report task by itself is not sufficient. You will have to configure and run a coverage Ant task in order to enable coverage data to be recorder into the jacoco.exec file. See here

like image 39
Ori Dar Avatar answered Sep 19 '22 17:09

Ori Dar