如何設置Ant任務以生成Emma代碼覆蓋率報告?如何使用Ant生成Emma代碼覆蓋率報告?
26
A
回答
14
回答有關在源和儀器目錄問題(這些可以切換到任何你的標準目錄結構):
<property file="build.properties" />
<property name="source" location="src/main/java" />
<property name="test.source" location="src/test/java" />
<property name="target.dir" location="target" />
<property name="target" location="${target.dir}/classes" />
<property name="test.target" location="${target.dir}/test-classes" />
<property name="instr.target" location="${target.dir}/instr-classes" />
類路徑:
<path id="compile.classpath">
<fileset dir="lib/main">
<include name="*.jar" />
</fileset>
</path>
<path id="test.compile.classpath">
<path refid="compile.classpath" />
<pathelement location="lib/test/junit-4.6.jar" />
<pathelement location="${target}" />
</path>
<path id="junit.classpath">
<path refid="test.compile.classpath" />
<pathelement location="${test.target}" />
</path>
首先你需要設置Ant可以找到Emma庫:
<path id="emma.lib" >
<pathelement location="${emma.dir}/emma.jar" />
<pathelement location="${emma.dir}/emma_ant.jar" />
</path>
然後導入任務:
<taskdef resource="emma_ant.properties" classpathref="emma.lib" />
然後儀器代碼:
<target name="coverage.instrumentation">
<mkdir dir="${instr.target}"/>
<mkdir dir="${coverage}"/>
<emma>
<instr instrpath="${target}" destdir="${instr.target}" metadatafile="${coverage}/metadata.emma" mode="copy">
<filter excludes="*Test*"/>
</instr>
</emma>
<!-- Update the that will run the instrumented code -->
<path id="test.classpath">
<pathelement location="${instr.target}"/>
<path refid="junit.classpath"/>
<pathelement location="${emma.dir}/emma.jar"/>
</path>
</target>
然後運行目標與適當的VM參數,如:
<jvmarg value="-Demma.coverage.out.file=${coverage}/coverage.emma" />
<jvmarg value="-Demma.coverage.out.merge=true" />
最後生成報告:
<target name="coverage.report" depends="coverage.instrumentation">
<emma>
<report sourcepath="${source}" depth="method">
<fileset dir="${coverage}" >
<include name="*.emma" />
</fileset>
<html outfile="${coverage}/coverage.html" />
</report>
</emma>
</target>
0
Emma 2.1引入了另一種方式o f獲取運行時間覆蓋信息(.ec文件)。可以遠程請求來自計算機應用程序運行的計算機給定端口的數據。所以沒有必要停止虛擬機。
要獲得運行時的覆蓋數據,你需要插入下面的代碼片段在Ant腳本的測試,並生成覆蓋報告的運行之間的文件:
<emma>
<ctl connect="${emma.rt.host}:${emma.rt.port}" >
<command name="coverage.get" args="${emma.ec.file}" />
<command name="coverage.reset" />
</ctl>
</emma>
其他步驟與艾瑪2.0。他們在previous post
更多信息完美地描述關於艾瑪2.1功能:http://sourceforge.net/project/shownotes.php?group_id=108932&release_id=336859
2
的User Guide has a good example of how to set up your build script,這樣你不僅單獨從執行所構建的代碼,但它也都包含在同一個<target>
讓你不不必運行一系列不同的目標,但是你可以做一些類似於ant emma tests
的東西(例如,如果ant tests
是你通常運行單元測試的方式)。
這裏是他們的榜樣:
<target name="emma" description="turns on EMMA instrumentation/reporting" >
<property name="emma.enabled" value="true" />
<!-- EMMA instr class output directory: -->
<property name="out.instr.dir" value="${basedir}/outinstr" />
<mkdir dir="${out.instr.dir}" />
</target>
<target name="run" depends="init, compile" description="runs the examples" >
<emma enabled="${emma.enabled}" >
<instr instrpathref="run.classpath"
destdir="${out.instr.dir}"
metadatafile="${coverage.dir}/metadata.emma"
merge="true"
/>
</emma>
<!-- note from matt b: you could just as easily have a <junit> task here! -->
<java classname="Main" fork="true" >
<classpath>
<pathelement location="${out.instr.dir}" />
<path refid="run.classpath" />
<path refid="emma.lib" />
</classpath>
<jvmarg value="-Demma.coverage.out.file=${coverage.dir}/coverage.emma" />
<jvmarg value="-Demma.coverage.out.merge=true" />
</java>
<emma enabled="${emma.enabled}" >
<report sourcepath="${src.dir}" >
<fileset dir="${coverage.dir}" >
<include name="*.emma" />
</fileset>
<txt outfile="${coverage.dir}/coverage.txt" />
<html outfile="${coverage.dir}/coverage.html" />
</report>
</emma>
</target>
相關問題
- 1. 如何從Hudson生成Emma代碼覆蓋率報告?
- 2. EMMA代碼覆蓋率報告使用的顏色圖例
- 3. 非源代碼類包含在emma xml覆蓋率報告中
- 4. 如何強制Emma代碼覆蓋率報告忽略某些方法?
- 5. 如何使用Hudson的Maven生成Cobertura代碼覆蓋率報告
- 6. 無法運行EMMA代碼覆蓋率
- 7. 在PHPUnit之外生成代碼覆蓋率報告
- 8. 生成jstestdriver覆蓋率報告
- 9. pydev代碼覆蓋率報告爲零
- 10. 艾瑪代碼覆蓋率報告
- 11. 過濾來自Emma代碼覆蓋率報告的junit測試類
- 12. 使用gradle爲單個單元測試生成Jacoco代碼覆蓋率報告
- 13. 用Fastlane/Jenkins生成代碼覆蓋率
- 14. 我如何生成失敗的Jenkins版本的代碼覆蓋率報告
- 15. 如何從visual studio .coverage文件生成覆蓋率報告,該文件與emma生成的文件相似?
- 16. 使用巴澤爾生成覆蓋率報告
- 17. 使用cobertura插件轉到Jenkins的代碼覆蓋率報告
- 18. 錯誤,而代碼覆蓋率報告使用lcov
- 19. 代碼覆蓋率:.NET代碼覆蓋率和SonarQube VSTS集成
- 20. 如何從Clover覆蓋率報告中排除代碼?
- 21. 如何在Android Studio 2.3中配置代碼覆蓋率報告?
- 22. 如何在Hudson中彙總代碼覆蓋率報告?
- 23. Cobertura with Ant Script:xml/html覆蓋率報告總是顯示0%覆蓋率
- 24. 爲什麼PHPUnit在生成覆蓋率報告時執行代碼?
- 25. 無法生成來自Clover Maven插件的代碼覆蓋率HTML報告
- 26. PHPSpec和覆蓋率報告
- 27. 如何使用gcov/lcov爲fork()的孩子生成覆蓋率報告?
- 28. 無法獲得代碼覆蓋報告使用jmockit覆蓋jar
- 29. 如何使用EMMA代碼覆蓋更改Ant腳本,以便找到運行時覆蓋數據?
- 30. 如何觸發源代碼的dotcover代碼覆蓋率分析並生成報告
看起來不像你定義$ {}覆蓋 – 2012-10-02 22:22:35