2011-11-20 69 views
1

我正在嘗試一些代碼覆蓋率分析的第一次,我正在努力使用ANT獲取cobertura。我的問題可能很愚蠢,但想到這裏問。我的ANT腳本中有以下內容。在通過cobertura閱讀時,下一步是儀器。代碼覆蓋儀器是什麼?Cobertura - 代碼覆蓋儀表

<target name="cobertura" depends="checkstyle"> 
    <property name="cobertura.dir" location="C:\\Softwares- packages\\Corbetura\\cobertura-1.9.4.1" /> 
    <path id ="cobertura.classpath"> 
    <fileset dir="${cobertura.dir}"> 
     <include name="cobertura.jar"/> 
     <include name="lib/**/*.jar"/> 
    </fileset> 
    </path>  
    <taskdef resource="tasks.properties" classpathref="cobertura.classpath"/> 

</target> 

回答

0

我相信你正在尋找「cobertura-instrument」任務。請參閱here

2

cobertura修改您的類文件,以便它可以計算覆蓋率。我通常會「測試」一個用於執行測試的jar文件的副本,並使用一個尚未用作工具的副本作爲構建工件。

這是我第一次通過螞蟻設立的Cobertura我的構建文件:

的的Cobertura儀器儀表目標我的代碼和像你說的寫儀表類單獨的目錄。

junit目標編譯測試,然後測試測試,然後運行測試,然後生成報告。這些步驟都是通過向junit聲明相關目標來完成的。

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

<taskdef classpathref="cobertura.classpath" resource="tasks.properties" /> 

<!-- Delete an existing coburtura datafile --> 
<delete file="${cobertura.datafile}"/> 
<antcall target="cobertura.clean"/> 

<!-- Instrument the code with cobertura to test for coverage --> 
<cobertura-instrument todir="${cobertura.instrumented.classes}" datafile="${cobertura.datafile}"> 
    <fileset dir="${build.dir}/classes/"> 
     <include name="**/*.class"/> 
    </fileset> 
</cobertura-instrument> 

<fileset dir="${src.dir}"> 
     <include name="**/*.java" /> 
</fileset> 
<fileset dir="${tests.src.dir}"> 
    <include name="**/*.java" /> 
</fileset> 

+0

非常感謝Eric.Please糾正我,如果我錯了。一旦構建完成,corebetura將創建另一個二進制副本並執行單元測試。根據它,它會生成報告。那麼我可以告訴instrumentation正在複製二進制文件並執行測試執行嗎? – techrawther