Java 如何在junit目标中集成jacoco和ant
我有build.xml,它专门用于为我的项目运行junit测试用例,现在我必须将它与jacoco代码覆盖率集成,我已经将jacaco ant.jar放在ant home libe路径中,现在您可以建议我如何集成或如何更改下面的目标以与jacoco兼容我的目标如下所示Java 如何在junit目标中集成jacoco和ant,java,junit,jacoco,Java,Junit,Jacoco,我有build.xml,它专门用于为我的项目运行junit测试用例,现在我必须将它与jacoco代码覆盖率集成,我已经将jacaco ant.jar放在ant home libe路径中,现在您可以建议我如何集成或如何更改下面的目标以与jacoco兼容我的目标如下所示 <taskdef resource="testngtasks" classpathref="junit.classpath" /> <target name="run.nightly" depends="clea
<taskdef resource="testngtasks" classpathref="junit.classpath" />
<target name="run.nightly" depends="clean,clean.unit,clean.dbsupport,clean.artifacts,init, init.unit,init.dbsupport,init.artifacts, compile, emma" >
<antcall target="findbugs"/>
<emma enabled="${emma.enabled}">
<instr instrpathref="emma.run.classpath" destdir="${out.instr.dir}" metadatafile="${coverage.dir}/metadata.emma" merge="true" mode="overwrite" verbosity="verbose">
<filter excludes="${emma.exclude}" />
</instr>
</emma>
<junit printsummary="true" fork="yes" dir="${basedir}" haltonfailure="false" failureproperty="junitsFailed" errorProperty="junitsFailed">
<sysproperty key="emma.coverage.out.file" value="${coverage.dir}/coverage.emma" />
<sysproperty key="emma.coverage.out.merge" value="true" />
<formatter type="xml" />
<formatter type="plain" usefile="false" />
<classpath>
<pathelement location="${out.instr.dir}" />
<path refid="junit.classpath" />
<path refid="emma.lib" />
<pathelement location="${build}/config" />
</classpath>
<batchtest fork="yes" todir="${reports.test}/logs">
<fileset dir="${src.tests}">
<include name="**/*Test.java" />
</fileset>
</batchtest>
</junit>
<antcall target="report.nightly" />
<emma enabled="${emma.enabled}">
<report sourcepath="${src}">
<fileset dir="${coverage.dir}">
<include name="*.emma" />
</fileset>
<html outfile="${artifacts.coverage}/coverage.html" />
<xml outfile="${artifacts.coverage}/coverage.xml" />
</report>
</emma>
<fail message="Some Test Cases Failed" if="junitsFailed" />
您可以使用jacoco提供的覆盖率任务来获得junit测试用例的代码覆盖率,如下所示:
<coverage destfile="${result.exec.file}">
<junit printsummary="true" haltonfailure="no" haltonerror="no" showoutput="true" fork="yes">
<classpath>
<path refid="module_classpath"/>
<pathelement location="${module.junit.jar}"/>
<pathelement location="${module.xmlunit.jar}"/>
<pathelement location="${module.test.classes.dir}"/>
<pathelement location="${module.instr.dir}"/>
<pathelement location="${module.classes.dir}"/>
</classpath>
<test name="com.test.AUTestClass" todir="${module.test.reports.dir}/xml" >
<formatter type="xml"/>
</test>
</junit>
你读过吗?读过,但还是不能集成