使用Jacoco和ant构建实现Junit覆盖
我在使用jacoco:coverage for code coverage执行junit时遇到了这个特定的问题。尝试了一些事情,但还没有成功 我有这个junit构建脚本使用Jacoco和ant构建实现Junit覆盖,ant,junit4,jacoco,Ant,Junit4,Jacoco,我在使用jacoco:coverage for code coverage执行junit时遇到了这个特定的问题。尝试了一些事情,但还没有成功 我有这个junit构建脚本 <target name="executeJunitMain" depends="createJunitLibs" description="Executes All Junit and prepare report."> <junit fork="yes" haltonfailure
<target name="executeJunitMain" depends="createJunitLibs" description="Executes All Junit and prepare report.">
<junit fork="yes" haltonfailure="off" failureProperty="junit.failure" includeantruntime="true" maxmemory="256m">
<classpath refid="compile.class.path" />
<formatter type="xml" />
<jvmarg value="-javaagent:${external.junit.lib.dir}/jmockit.jar"/>
<sysproperty key="jacoco-agent.destfile" file="${coverage.dir}/jacoco.exec"/>
<batchtest fork="yes" todir="${report.dir}" >
<fileset dir="${dest.dir}">
<include name="**/Test*.class" />
<exclude name="**/AllTests.class" />
<exclude name="**/*$*.class"/>
</fileset>
</batchtest>
</junit>
<antcall target="report"/>
</target>
<!-- Execute the coverage report.-->
<target name="report" description="Collect Coverage Report">
<!-- Creates the Junit Report -->
<junitreport todir="${report.dir}">
<fileset dir="${report.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${report.dir}/html"/>
</junitreport>
<!-- Creates the coverage Report.-->
<mkdir dir="${report.dir}/coverage"/>
<jacoco:report>
<executiondata>
<file file="${coverage.dir}/jacoco.exec" />
</executiondata>
<structure name="Code Coverage">
<classfiles>
<zipfileset src="${sources.lib.dir}/${test.jar.name}.jar"/>
</classfiles>
</structure>
<html destdir="${report.dir}/coverage" />
</jacoco:report>
</target>
但有时它工作得很完美。我不确定它什么时候起作用,什么时候不起作用。任何帮助都将不胜感激
谢谢我发现了导致jacoco失败的问题。我在类路径中导入了一些插入指令的JAR,这些JAR不是junit执行或覆盖所必需的。这些插入指令的JAR导致jacoco会话不正确,因为我们还将jmockit集成作为模拟框架。下面的链接非常有助于发现问题
我也在尝试使用ant build和jacoco构建android单元测试,你能给我分享一下我们的build.xml吗。Bcz我是新来的杰科科。
BUILD FAILED
C:\Users\user\Codebases\junit.xml:111: The following error occurred while executing this line:
C:\Users\user\Codebases\junit.xml:147: The following error occurred while executing this line:
C:\Users\user\Codebases\junit.xml:164: Unable to read execution data file C:\Users\user\CodeBases\ju
nit\coverage\jacoco.exec