Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jacoco: unable to read execution data file, ant task

Info: java version: 1.8.0_66 ant version: 1.9.6

What I want to do:

Provide a code coverage report for the server's code that is running on AWS windows 2k12 server.

What I did:

  • Stop the server completely.
  • Put jacocoagent.jar into server's bin folder. Note: this is inside Program Files folder
  • Append -javaagent settings to JAVA_OPTS that is used during server start up.
  • Start the server.
  • Run my sample test from my local laptop.
  • Stop the server completely. This produced a 184kb jacoco.exec.
  • Copied my build.xml to the same directory where the jacoco.exec is located. C:/path/to/exec/jacoco.exec
  • Copied jacocoant.jar to C:/path/to/jacocoant.jar
  • cd into C:/path/to/exec/ and run command "ant"

Result:

Got error unable to read execution data file C:/path/to/exec/jacoco.exec

Build.xml:

<project name="Example" default="rebuild" xmlns:jacoco="antlib:org.jacoco.ant">

<description>
  Example Ant build file that demonstrates how a JaCoCo coverage report
  can be itegrated into an existing build in three simple steps.
</description>

<property name="result.dir" location="." />
<property name="result.classes.dir" location="${result.dir}/path/to/classes" />
<property name="result.report.dir" location="${result.dir}/report" />
<property name="result.exec.file" location="${result.dir}/jacoco.exec" />

<!-- Step 1: Import JaCoCo Ant tasks -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
    <classpath path="../jacocoant.jar" />
</taskdef>

<target name="clean">
    <delete dir="${result.report.dir}" />
</target>

<target name="report">
    <!-- Step 3: Create coverage report -->
    <jacoco:report>

        <!-- This task needs the collected execution data and ... -->
        <executiondata>
            <file file="${result.exec.file}" />
        </executiondata>

        <!-- the class files and optional source files ... -->
        <structure name="JaCoCo Code Coverage Report">
            <classfiles>
                <fileset dir="${result.classes.dir}" >
                    </fileset>
            </classfiles>
            <sourcefiles encoding="UTF-8">
                <fileset dir="${src.dir}" />
            </sourcefiles>
        </structure>

        <!-- to produce reports in different formats. -->
        <html destdir="${result.report.dir}" />
        <csv destfile="${result.report.dir}/report.csv" />
        <xml destfile="${result.report.dir}/report.xml" />
    </jacoco:report>
</target>

I am not sure if the problem is with exec file (it is corrupted maybe) or is with my entire setup. Any help to identify and help solving the problem is appreciated!!!

Thanks!

like image 249
DMeng Avatar asked Mar 17 '16 17:03

DMeng


People also ask

Why does JaCoCo not show coverage?

Why does the coverage report not show highlighted source code? Make sure the following prerequisites are fulfilled to get source code highlighting in JaCoCo coverage reports: Class files must be compiled with debug information to contain line numbers. Source files must be properly supplied at report generation time.

What is JaCoCo ant?

JaCoCo comes with Ant tasks to launch Java programs with execution recording and for creating coverage reports from the recorded data. Execution data can be collected and managed with the tasks coverage , agent , dump and merge . Reports in different formats are created with the report task.

How do I check my JaCoCo coverage?

JaCoCo reports help us visually analyze code coverage by using diamonds with colors for branches, and background colors for lines: Red diamond means that no branches have been exercised during the test phase. Yellow diamond shows that the code is partially covered – some branches have not been exercised.


2 Answers

I got this when using gradle and jaCoCo.

I deleted the build/ directory and reran ./gradlew jacocoTestReport, this time passing.

like image 92
noqcks Avatar answered Oct 21 '22 23:10

noqcks


Similar to @sofia's solution but for gradle: I removed the version after tool version. Instead of

allprojects {
    jacoco {
        toolVersion = '0.7.1.201405082137'
    }
}

I used the following

allprojects {
    jacoco {
        toolVersion = '0.7.1'
    }
}
like image 22
Josh Wang Avatar answered Oct 22 '22 00:10

Josh Wang