gpt4 book ai didi

java - 如何在 junit 目标中将 jacoco 与 ant 集成

转载 作者:行者123 更新时间:2023-12-01 12:45:59 25 4
gpt4 key购买 nike

我有专门为我的项目运行junit测试用例的build.xml,现在我必须将它与jacoco代码覆盖率集成,我已将jacaco ant.jar放在ant home libe路径中,现在可以吗建议我如何集成或如何更改以下目标以与 jacoco 兼容我的目标如下所示..

<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>

关于java - 如何在 junit 目标中将 jacoco 与 ant 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24702087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com