title: Jacoco - Zero Percent Coverage
body: <p>I am trying to integrate jacoco to our ant build and evaluate it with a simple test project. </p>
  
  <p>The compilation and the other output looks promising, but when I look at the coverage it is always zero.</p>
  
  <pre><code>package alg;
  
  public class SpecialAlgorithm {
      public SpecialAlgorithm() {}
  
      public int uncoveredMethod(int i) {
          return i * i;
      }
  
      public int sum(int i, int j) {
          return i + j;
      }   
  }
  </code></pre>
  
  <p>Testcase:</p>
  
  <pre><code>package alg;
  
  import static org.junit.Assert.assertEquals;
  import org.junit.Test;
  import alg.SpecialAlgorithm;
  
  public class SpecialAlgorithmTest {
      @Test
      public void testSum() {
          SpecialAlgorithm alg = new SpecialAlgorithm();
          int sum = alg.sum(1, 2);
          assertEquals(3, sum);
      }
  }
  </code></pre>
  
  <p>Ant script:</p>
  
  <pre><code>&lt;project xmlns:jacoco="antlib:org.jacoco.ant" name="Code Coverage with JaCoCo"
      default="rebuild"&gt;
      &lt;property name="src.dir" location="../java" /&gt;
      &lt;property name="test.dir" location="../../test/java" /&gt;
      &lt;property name="result.dir" location="c:/temp/jacoco/target" /&gt;
      &lt;property name="result.classes.dir" location="${result.dir}/classes" /&gt;
      &lt;property name="result.report.dir" location="${result.dir}/site/jacoco" /&gt;
      &lt;property name="result.exec.file" location="${result.dir}/jacoco.exec" /&gt;
      &lt;!-- Step 1: Import JaCoCo Ant tasks --&gt;
      &lt;taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml"&gt;
          &lt;classpath path="../../../lib/jacocoant.jar" /&gt;
      &lt;/taskdef&gt;
      &lt;target name="clean"&gt;
          &lt;delete dir="${result.dir}" /&gt;
          &lt;mkdir dir="${result.dir}" /&gt;
          &lt;mkdir dir="${result.dir}/site/jacoco/" /&gt;
      &lt;/target&gt;
      &lt;target name="compile" depends="clean"&gt;
          &lt;mkdir dir="${result.classes.dir}" /&gt;
          &lt;javac srcdir="${src.dir}" destdir="${result.classes.dir}"
              debug="true" includeantruntime="false"&gt;
              &lt;classpath&gt;
                  &lt;pathelement location="${result.classes.dir}" /&gt;
              &lt;/classpath&gt;
          &lt;/javac&gt;
      &lt;/target&gt;
      &lt;target name="test" depends="compile"&gt;
          &lt;taskdef name="junit"
              classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"&gt;
              &lt;classpath&gt;
                  &lt;pathelement location="../../../lib/junit.jar" /&gt;
                  &lt;pathelement location="../../../bin" /&gt;
                  &lt;pathelement location="${result.classes.dir}" /&gt;
              &lt;/classpath&gt;
          &lt;/taskdef&gt;
  
          &lt;jacoco:coverage destfile="${result.dir}/jacoco.exec"
              xmlns:jacoco="antlib:org.jacoco.ant"&gt;
              &lt;junit fork="yes" forkmode="once" dir="." failureProperty="test.failed"&gt;
                  &lt;classpath&gt;
                      &lt;pathelement location="../../../lib/junit.jar" /&gt;
                      &lt;pathelement location="../../../bin" /&gt;
                      &lt;pathelement location="${result.classes.dir}" /&gt;
                  &lt;/classpath&gt;
  
                  &lt;formatter type="xml" /&gt;
                  &lt;batchtest todir="${result.report.dir}"&gt;
                      &lt;fileset dir="${test.dir}"/&gt;
                  &lt;/batchtest&gt;
              &lt;/junit&gt;
          &lt;/jacoco:coverage&gt;
          &lt;!-- Step 3: Create coverage report --&gt;
          &lt;jacoco:report&gt;
              &lt;!-- This task needs the collected execution data and ... --&gt;
              &lt;executiondata&gt;
                  &lt;file file="${result.exec.file}" /&gt;
              &lt;/executiondata&gt;
              &lt;!-- the class files and optional source files ... --&gt;
              &lt;structure name="JaCoCo Ant Example"&gt;
                  &lt;classfiles&gt;
                      &lt;fileset dir="../../../bin" /&gt;
                  &lt;/classfiles&gt;
                  &lt;sourcefiles encoding="UTF-8"&gt;
                      &lt;fileset dir="${src.dir}" /&gt;
                  &lt;/sourcefiles&gt;
              &lt;/structure&gt;
              &lt;!-- to produce reports in different formats. --&gt;
              &lt;html destdir="${result.report.dir}" /&gt;
              &lt;csv destfile="${result.report.dir}/report.csv" /&gt;
              &lt;xml destfile="${result.report.dir}/report.xml" /&gt;
          &lt;/jacoco:report&gt;
      &lt;/target&gt;
      &lt;target name="rebuild" depends="test" /&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>UPDATE: After upgrading to the newer version I get a warning which may indicate what my mistake is.</p>
  
  <p>Console output:</p>
  
  <pre><code>Buildfile: JacocoEvaluation\src\main\resources\coverage.xml
  clean:
     [delete] Deleting directory c:\temp\jacoco\target
      [mkdir] Created dir: c:\temp\jacoco\target
      [mkdir] Created dir: c:\temp\jacoco\target\site\jacoco
  compile:
      [mkdir] Created dir: c:\temp\jacoco\target\classes
      [javac] Compiling 1 source file to c:\temp\jacoco\target\classes
  test:
  [jacoco:coverage] Enhancing junit with coverage
  [jacoco:report] Loading execution data file c:\temp\jacoco\target\jacoco.exec
  [jacoco:report] Writing bundle 'JaCoCo Ant Example' with 1 classes
  [jacoco:report] Classes in bundle 'JaCoCo Ant Example' do no match with execution data. For report generation the same class files must be used as at runtime.
  [jacoco:report] Execution data for class alg/SpecialAlgorithm does not match.
  rebuild:
  BUILD SUCCESSFUL
  Total time: 1 second
  </code></pre>
  
  <p>The directory structure (like maven):</p>
  
  <p>main/java/ Class to Test
  test/java/ Testcase</p>
  
  <p>Any ideas what I am doing wrong? The plugin works fine.</p>
  
  <p>UPDATE: Works now. I had the wrong directory referenced in the report structure. The newer version of jacoco printed a warning which helped to spot the problem.</p>