如何使用 EMMA 代码覆盖率更改 Ant 脚本,以便它可以找到运行时覆盖率数据?
我有以下脚本:
<?xml version="1.0" encoding="UTF-8"?>
<taskdef resource="emma_ant.properties">
<classpath>
<pathelement location="lib/emma.jar" />
<pathelement location="lib/emma_ant.jar" />
</classpath>
</taskdef>
<target name="compile">
<mkdir dir="build"/> <!-- vytvori adresar build -->
<mkdir dir="build/classes"/>
<mkdir dir="build/test"/>
<javac destdir="build/classes" srcdir="src" debug="true" /> <!-- prelozi zdrojove kody -->
<javac destdir="build/test" srcdir="test"> <!-- prelozi testy -->
<classpath> <!-- pro prelozeni testu je potreba junit a prelozena aplikace -->
<pathelement location="lib/junit-4.5.jar" />
<pathelement location="build/classes" />
</classpath>
</javac>
</target>
<target name="build" depends="compile">
<jar destfile="tetris.jar" basedir="build/classes"> <!-- zabali aplikaci do jaru -->
<manifest>
<attribute name="Main-Class" value="tetris.Main"/>
<attribute name="Class-Path" value="lib/mysql-connector-java-5.1.6-bin.jar lib/derbyclient.jar"/>
</manifest>
</jar>
</target>
<target name="jar" depends="build"></target>
<target name="run" depends="compile">
<java classname="tetris.Main" classpath="build/classes"> <!-- spusti aplikaci -->
<classpath>
<pathelement location="lib/mysql-connector-java-5.1.6-bin.jar" />
<pathelement location="lib/derbyclient.jar" />
</classpath>
</java>
</target>
<target name="instrument" depends="compile">
<mkdir dir="build/instrumented"/>
<emma verbosity="verbose"> <!-- vytvori tridy upravene pro sledovani coverage -->
<instr instrpath="build/classes"
destdir="build/instrumented"
metadatafile="build/metadata.emma"
merge="true" />
</emma>
</target>
<target name="test" depends="instrument">
<mkdir dir="reports" />
<mkdir dir="reports/junit" />
<junit printsummary="yes" haltonfailure="no" fork="true"> <!-- pusti JUnit testy -->
<classpath>
<pathelement location="build/test" />
<pathelement location="build/classes" />
<pathelement location="build/instrumented" />
<pathelement location="lib/junit-4.5.jar" />
<pathelement location="lib/emma.jar" />
<pathelement location="lib/emma_ant.jar" />
</classpath>
<formatter usefile="false" type="brief" />
<formatter type="plain"/>
<batchtest fork="yes" todir="reports/junit"> <!-- reporty budou v adresari reports/junit -->
<fileset dir="test">
<include name="**/TetrisSuite.java"/>
</fileset>
</batchtest>
<jvmarg value="-Demma.coverage.out.file=build/coverage.emma"/>
<jvmarg value="-Demma.coverage.out.merge=true" />
</junit>
<emma enabled="true" verbosity="verbose"> <!-- vygeneruje report emmy -->
<report sourcepath="src">
<fileset dir="build" includes="*.emma" />
<html outfile="reports/coverage.html" />
</report>
</emma>
</target>
<target name="clean">
<delete dir="build"/> <!-- smaze adresar build -->
<delete dir="reports"/>
<delete file="tetris.jar"/>
</target>
它输出以下消息:
processing input file [...NetBeansProjects/Tetris3/build/metadata.emma] ...
loaded 25 metadata entries
1 file(s) read and merged in 5 ms
nothing to do: no runtime coverage data found in any of the data files
出了什么问题以及如何修复它?
I have following script:
<?xml version="1.0" encoding="UTF-8"?>
<taskdef resource="emma_ant.properties">
<classpath>
<pathelement location="lib/emma.jar" />
<pathelement location="lib/emma_ant.jar" />
</classpath>
</taskdef>
<target name="compile">
<mkdir dir="build"/> <!-- vytvori adresar build -->
<mkdir dir="build/classes"/>
<mkdir dir="build/test"/>
<javac destdir="build/classes" srcdir="src" debug="true" /> <!-- prelozi zdrojove kody -->
<javac destdir="build/test" srcdir="test"> <!-- prelozi testy -->
<classpath> <!-- pro prelozeni testu je potreba junit a prelozena aplikace -->
<pathelement location="lib/junit-4.5.jar" />
<pathelement location="build/classes" />
</classpath>
</javac>
</target>
<target name="build" depends="compile">
<jar destfile="tetris.jar" basedir="build/classes"> <!-- zabali aplikaci do jaru -->
<manifest>
<attribute name="Main-Class" value="tetris.Main"/>
<attribute name="Class-Path" value="lib/mysql-connector-java-5.1.6-bin.jar lib/derbyclient.jar"/>
</manifest>
</jar>
</target>
<target name="jar" depends="build"></target>
<target name="run" depends="compile">
<java classname="tetris.Main" classpath="build/classes"> <!-- spusti aplikaci -->
<classpath>
<pathelement location="lib/mysql-connector-java-5.1.6-bin.jar" />
<pathelement location="lib/derbyclient.jar" />
</classpath>
</java>
</target>
<target name="instrument" depends="compile">
<mkdir dir="build/instrumented"/>
<emma verbosity="verbose"> <!-- vytvori tridy upravene pro sledovani coverage -->
<instr instrpath="build/classes"
destdir="build/instrumented"
metadatafile="build/metadata.emma"
merge="true" />
</emma>
</target>
<target name="test" depends="instrument">
<mkdir dir="reports" />
<mkdir dir="reports/junit" />
<junit printsummary="yes" haltonfailure="no" fork="true"> <!-- pusti JUnit testy -->
<classpath>
<pathelement location="build/test" />
<pathelement location="build/classes" />
<pathelement location="build/instrumented" />
<pathelement location="lib/junit-4.5.jar" />
<pathelement location="lib/emma.jar" />
<pathelement location="lib/emma_ant.jar" />
</classpath>
<formatter usefile="false" type="brief" />
<formatter type="plain"/>
<batchtest fork="yes" todir="reports/junit"> <!-- reporty budou v adresari reports/junit -->
<fileset dir="test">
<include name="**/TetrisSuite.java"/>
</fileset>
</batchtest>
<jvmarg value="-Demma.coverage.out.file=build/coverage.emma"/>
<jvmarg value="-Demma.coverage.out.merge=true" />
</junit>
<emma enabled="true" verbosity="verbose"> <!-- vygeneruje report emmy -->
<report sourcepath="src">
<fileset dir="build" includes="*.emma" />
<html outfile="reports/coverage.html" />
</report>
</emma>
</target>
<target name="clean">
<delete dir="build"/> <!-- smaze adresar build -->
<delete dir="reports"/>
<delete file="tetris.jar"/>
</target>
It outputs this message:
processing input file [...NetBeansProjects/Tetris3/build/metadata.emma] ...
loaded 25 metadata entries
1 file(s) read and merged in 5 ms
nothing to do: no runtime coverage data found in any of the data files
What's wrong and how to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您正在学习非仪器课程。
可能是因为
junit
任务中的classpath
已编译类 (build/classes
) 领先 (构建/检测
)。也许在该类路径中反转这些?编辑
我下载了 emma 并设置了一个包含一个源类和一个测试类的基本项目。我尝试使用问题中提供的构建来运行它。我所做的唯一更改是将主体包装在
中,并以test
作为默认目标。运行时,我收到了与问题中类似的消息:然后,我设置 junit 类路径,将检测的类放在普通类之前:
并重新运行:
看起来这为我修复了它。我运行了一个测试:
如果您在 ant 输出中没有看到任何类似的行,也许您没有与
**/TetrisSuite.java
模式匹配的测试?It looks like you're picking up the non-instrumented classes.
Could be because the
classpath
in yourjunit
task has the compiled classes (build/classes
) ahead of the instrumented (build/instrumented
). Maybe reverse these in that classpath?EDIT
I downloaded emma and set up a basic project with one source class and one test class. I tried to run it using the build provided in the question. The only change I made was to wrap the body in a
<project>
withtest
as the default target. When run I got a similar message to in the question:I then set the junit classpath to put the instrumented classes ahead of the vanilla:
And reran:
Looks like that fixed it for me. I had one test that ran:
If you're not seeing any lines like that in the ant output perhaps you have no tests that match the
**/TetrisSuite.java
pattern?