Ant Cobertura为代码覆盖率生成我的报告,但覆盖率显示为0%
我的所有报告都会生成,但我的覆盖率显示为0%。我甚至创建了一个虚拟测试,以确保它不是我编写测试的方式,并且它不会显示我正在讨论的一个虚拟类。以下是我的Ant构建:Ant Cobertura为代码覆盖率生成我的报告,但覆盖率显示为0%,ant,junit,cobertura,Ant,Junit,Cobertura,我的所有报告都会生成,但我的覆盖率显示为0%。我甚至创建了一个虚拟测试,以确保它不是我编写测试的方式,并且它不会显示我正在讨论的一个虚拟类。以下是我的Ant构建: <?xml version="1.0" encoding="UTF-8" ?> <project name="My Project Name" default="run.cobertura" basedir="."> <description>My Description</desc
<?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>
我的描述
我注意到的一件事是,在run.cobertura目标的dependens列表中,您在编译编译类之前插入编译类。如果您运行两次,假设第一次运行的编译类没有被清除,但看起来不太正确,那么这可能会起作用。在第一次运行时,如果没有插入指令的类,您的报告将是空的。我有相同的ant构建脚本。它在我的本地工作站上工作,但在jenkins服务器上没有。
但服务器有JDK7和工作站jdk6。将jenkins服务器上的jdk更改为jdk6后,代码覆盖率将毫无问题地生成。编译java时必须启用调试
<javac **debug="on"** srcdir="${testcase-unit-only.path}" destdir="${testcase-unit-only.output.path}">
这确实是问题的一部分。谢谢