2011-07-01 4 views
2

모든 보고서가 생성되지만 내 서비스 범위는 0 %로 표시됩니다. 나는 심지어 그것이 나의 테스트가 쓰여지는 방식이 아니라는 것을 확인하기 위해 하나의 더미 테스트를 만들었고, 내가 다루고있는 하나의 더미 클래스에 대해서는 보여주지 않는다. 여기 내 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에 대한 목록을 따라 당신이 그들을 컴파일 전에 악기를 컴파일 된 클래스를 대상으로한다는 것입니다. 첫 실행에서 컴파일 된 클래스가 제거되지 않았다고 가정 할 때 두 번 실행하면 작동하지만 제대로는 보이지 않습니다. 계측 된 수업이 없으면 첫 번째 실행에서 보고서가 비어있게됩니다.

+0

를 컴파일 할 때의 디버깅을 설정해야합니다. 감사! –

0

동일한 개미 빌드 스크립트가 있습니다. 로컬 워크 스테이션에서 작동했지만 젠킨스 서버에서는 작동하지 않았습니다. 그러나 서버에는 jdk 7과 워크 스테이션 jdk6이 있습니다. jenkins 서버에서 jdk를 jdk6으로 변경 한 후 코드 커버리지가 아무 문제없이 생성됩니다.

0

당신은 자바에게이 실제로 문제의 일부

<javac **debug="on"** srcdir="${testcase-unit-only.path}" destdir="${testcase-unit-only.output.path}"> 
관련 문제