繁体   English   中英

使用 ant 的 jacoco.exec 文件的代码覆盖率报告

[英]Code coverage report from jacoco.exec file using ant

我正在尝试使用 ant 从 jacoco.exec 文件生成代码覆盖率报告。

我的蚂蚁构建是:

<?xml version="1.0"?>
<project xmlns:jacoco="antlib:org.jacoco.ant" name="Example Ant Build with JaCoCo" default="rebuild">

  <description>
Example Ant build file that demonstrates how a JaCoCo coverage report can be itegrated into an existing build in three simple steps.
</description>

  <property name="src.dir" location="./java"/>
  <property name="result.dir" location="./target"/>
  <property name="result.classes.dir" location="./classes"/>
  <property name="result.report.dir" location="${result.dir}/site/jacoco"/>
  <property name="result.exec.file" location="./jacoco.exec"/>

  <!--  Step 1: Import JaCoCo Ant tasks  -->
  <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
    <classpath path="./jacocoant.jar"/>
  </taskdef>

  <target name="compile">
    <mkdir dir="${result.classes.dir}"/>
    <javac srcdir="${src.dir}" destdir="${result.classes.dir}" debug="true" includeantruntime="false"/>
  </target>

  <target name="test" depends="compile">
    <!--
 Step 2: Wrap test execution with the JaCoCo coverage task 
-->
    <jacoco:coverage destfile="${result.exec.file}">
      <java classname="org.jacoco.examples.parser.Main" fork="true">
        <classpath path="${result.classes.dir}"/>
        <arg value="2 * 3 + 4"/>
        <arg value="2 + 3 * 4"/>
        <arg value="(2 + 3) * 4"/>
        <arg value="2 * 2 * 2 * 2"/>
        <arg value="1 + 2 + 3 + 4"/>
        <arg value="2 * 3 + 2 * 5"/>
      </java>
    </jacoco:coverage>
  </target>

  <target name="report" depends="test">
    <!--  Step 3: Create coverage report  -->
    <jacoco:report>
      <!--
 This task needs the collected execution data and ... 
-->
      <executiondata>
        <file file="${result.exec.file}"/>
      </executiondata>
      <!--  the class files and optional source files ...  -->
      <structure name="JaCoCo Ant Example">
        <classfiles>
          <fileset dir="${result.classes.dir}"/>
        </classfiles>
        <sourcefiles encoding="UTF-8">
          <fileset dir="${src.dir}"/>
        </sourcefiles>
      </structure>
      <!--  to produce reports in different formats.  -->
      <html destdir="${result.report.dir}"/>
      <csv destfile="${result.report.dir}/report.csv"/>
      <xml destfile="${result.report.dir}/report.xml"/>
    </jacoco:report>
  </target>

  <target name="rebuild" depends="compile,test,report"/>

</project>

但是在编译 ant build 时,我得到了与代码中未定义符号相关的错误。 我如何删除它们?

错误的一个例子是:

compile:
[javac] Compiling 13 source files to C:\Documents and Settings\user\Desktop\jacoco\classes
[javac] C:\Documents and Settings\user\Desktop\jacoco\java\file.java:13: error: package org.abc.def.ghi.primitives does not exist
[javac] import org.abc.def.ghi.primitives.Request;

这些导入来自我的代码并在内部定义,但 ant 无法识别它们。 我已经复制了所有的 .java 和 .class 文件。

任何指针将不胜感激。

不是代码覆盖率问题。 您的代码在编译步骤失败。 javac命令抛出错误。你需要先解决这个问题。

我不明白你的意思:

.... 我已经复制了所有的 .java 和 .class 文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM