在使用ant+clover的时候,经常碰到下面的异常:
BUILD FAILED
com.atlassian.clover.registry.NoSuchRegistryException: Clover registry file "/tmp/clover-db/ant-coverage.db" does not exist, cannot be read or is a directory.
Please ensure Clover has instrumented your source files.
You may need to remove existing .class files for this to occur.
at com.cenqua.clover.CloverDatabase.<init>(CloverDatabase.java:82)
at com.cenqua.clover.CloverDatabase.<init>(CloverDatabase.java:60)
at com.cenqua.clover.reporters.CloverReportConfig.getCoverageDatabase(CloverReportConfig.java:329)
at com.cenqua.clover.reporters.Current.getCoverageDatabase(Current.java:126)
at com.cenqua.clover.reporters.xml.XMLReporter.<init>(XMLReporter.java:52)
at com.cenqua.clover.reporters.CloverReporter.buildReporter(CloverReporter.java:70)
at com.cenqua.clover.tasks.CloverReportTask.generateReports(CloverReportTask.java:428)
at com.cenqua.clover.tasks.CloverReportTask.cloverExecute(CloverReportTask.java:385)
at com.cenqua.clover.tasks.CloverHtmlReportTask.cloverExecute(CloverHtmlReportTask.java:108)
at com.cenqua.clover.tasks.AbstractCloverTask.execute(AbstractCloverTask.java:55)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
at org.apache.tools.ant.Main.runBuild(Main.java:758)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Total time: 56 seconds
这个错误是因为,没有生成clover记录数据库造成的。
经过多次的实验,发现用下面的方法可以解决:
<target name="clover.with" depends="clover.tasks">
<delete file="${clover.db.file}"/>
<clover-instr initstring="${clover.db.file}" srcdir="${src.dir}"
destdir="${clover.tmp.dir}"></clover-instr>
</target>
<target name="clover.compile">
<javac srcdir="${clover.tmp.dir}"
destdir="${classes.dir}"
encoding="UTF-8"
includeantruntime="true"
failonerror="true"
verbose="false"
compiler="modern"
fork="true"
target="1.6"
nowarn="true">
<classpath refid="build.lib"/>
</javac>
</target>
这个地方,把clover.compile独立出来编译。有一个关键的地方是在粗体的部分,要指定一个临时目录,用来存放添加了stub的java类,也就说,独立一个地方存放插了桩的java类,然后对其编译,这样就能在后续的junit.test.only任务执行的时候生成clover记录数据库了。
希望对使用clover的朋友能有所帮助。
|----------------------------------------------------------------------------------------|
版权声明 版权所有 @zhyiwww
引用请注明来源 http://www.blogjava.net/zhyiwww
|----------------------------------------------------------------------------------------|
posted on 2010-12-14 15:19
zhyiwww 阅读(554)
评论(0) 编辑 收藏 所属分类:
软件测试 、
linux