2011-07-01 16 views
2

すべてのレポートが生成されますが、カバレッジは0%と表示されます。私はテストが作成された方法ではないことを確認するために1つのダミーテストを作成しましたが、私がカバーする1つのダミークラスについては表示されません。ここでは、このための私のAntビルドです:私は気付かCoberturaはコードカバレッジレポートを生成しますが、カバレッジは0%と表示されます

<?xml version="1.0" encoding="UTF-8" ?> 
<project name="My Project Name" default="run.cobertura" basedir="."> 

    <description>My Description</description> 

    <!-- target: init --> 

    <target name="init"> 

     <!-- create properties and directory structure --> 

     <property name="src.path" value="${basedir}/src" /> 
     <property name="lib.path" value="${basedir}/lib" /> 
     <property name="output.path" value="${basedir}/bin" /> 
     <property name="testcase-unit-only.path" value="${basedir}/testcase-unit-only" /> 
     <property name="testcase-unit-only.output.path" value="${basedir}/test-classes" /> 

     <property name="cobertura.lib.path" value="${basedir}/lib-cobertura" /> 
     <property name="cobertura.path" value="${basedir}/cobertura" /> 
     <property name="cobertura.output.path" value="${cobertura.path}/bin" /> 
     <property name="cobertura.reports.path" value="${cobertura.path}/reports" /> 
     <property name="cobertura.data.file" value="${cobertura.path}/cobertura.ser" /> 

     <delete dir="${testcase-unit-only.output.path}" /> 
     <delete dir="${cobertura.path}"/> 

     <mkdir dir="${testcase-unit-only.output.path}"/> 
     <mkdir dir="${cobertura.path}"/> 
     <mkdir dir="${cobertura.output.path}"/> 

     <!-- define classpath references --> 

     <path id="cp.lib.path"> 
      <fileset dir="${lib.path}"> 
       <include name="*.jar"/> 
      </fileset> 
     </path> 

     <path id="cp.classes.path"> 
      <pathelement path="${output.path}" /> 
     </path> 

     <path id="cp.classes.test.path"> 
      <pathelement path="${testcase-unit-only.output.path}" /> 
     </path> 

     <path id="cp.lib.cobertura.path"> 
      <fileset dir="${cobertura.lib.path}"> 
       <include name="*.jar"/> 
      </fileset> 
     </path> 

     <path id="cp.all.path"> 
      <path refid="cp.lib.path"/> 
      <path refid="cp.classes.path"/> 
      <path refid="cp.lib.cobertura.path"/> 
     </path> 

    </target> 

    <!-- target: run.cobertura-instrument --> 

    <target name="run.cobertura-instrument"> 

     <taskdef classpathref="cp.lib.cobertura.path" resource="tasks.properties"/> 

     <cobertura-instrument todir="${cobertura.output.path}" datafile="${cobertura.data.file}"> 
      <fileset dir="${output.path}"> 
       <include name="**/*.class" /> 
      </fileset> 
     </cobertura-instrument> 

    </target> 

    <!-- target: compile.classes --> 

    <target name="compile.classes"> 

     <javac srcdir="${src.path}" destdir="${output.path}"> 
      <classpath refid="cp.lib.path"/> 
     </javac> 

    </target> 

    <!-- target: compile.tests --> 

    <target name="compile.tests"> 

     <javac srcdir="${testcase-unit-only.path}" destdir="${testcase-unit-only.output.path}"> 
      <classpath refid="cp.all.path"/> 
     </javac> 

    </target> 

    <!-- target: run.junit --> 

    <target name="run.junit"> 

     <junit fork="true" dir="${basedir}" failureProperty="test.failed"> 

      <classpath location="${cobertura.output.path}"/> 
      <classpath location="${output.path}"/> 

      <sysproperty key="net.sourceforge.cobertura.datafile" file="${cobertura.data.file}" /> 

      <classpath refid="cp.lib.path"/> 
      <classpath refid="cp.classes.test.path"/> 
      <classpath refid="cp.lib.cobertura.path"/> 

      <formatter type="xml" /> 
      <!-- <formatter type="brief" usefile="false"/> --> 

      <batchtest todir="${testcase-unit-only.output.path}" unless="testcase"> 
       <fileset dir="${testcase-unit-only.output.path}"> 
        <include name="**/*UnitTest.java"/> 
       </fileset> 
      </batchtest> 

     </junit> 

    </target> 

    <!-- target: run.cobertura --> 

    <target name="run.cobertura" depends="init,run.cobertura-instrument,compile.classes,compile.tests,run.junit"> 

     <cobertura-report srcdir="src" destdir="${cobertura.reports.path}" datafile="${cobertura.data.file}"/> 

    </target> 

</project> 

答えて

3

ことの一つは、前run.coberturaターゲットのリストあなたの機器にコンパイルされたクラスに依存にあなたがそれらをコンパイルすることです。最初の実行からのコンパイルされたクラスがクリアされていないと仮定して、2回実行するとうまくいくかもしれませんが、かなり正しいとは思われません。計測されたクラスがない場合は、最初の実行時にレポートが空になります。

+0

をコンパイルするときにデバッグを設定する必要があります。ありがとう! –

0

私は同じant buildスクリプトを持っていました。私のローカルワークステーションで動作しましたが、jenkinsサーバーでは動作しませんでした。 しかし、サーバーにはjdk 7とワークステーションjdk6がありました。 jenkinsサーバーのjdkをjdk6に変更した後、問題なくコードカバレッジが生成されます。

0

あなたはこれが実際に問題の一部だったのjava

<javac **debug="on"** srcdir="${testcase-unit-only.path}" destdir="${testcase-unit-only.output.path}"> 
関連する問題