首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jacoco代码覆盖率

Jacoco代码覆盖率
EN

Stack Overflow用户
提问于 2016-09-30 19:23:10
回答 1查看 955关注 0票数 1
代码语言:javascript
复制
We are getting error: Code coverage error:

[jacoco:coverage] Enhancing java with coverage
     [java] Error: Could not find or load main class **\*.class
     [java] Java Result: 1
[jacoco:coverage] Enhancing junit with coverage
    [junit] Test **/*Test FAILED

我们正在使用build.xml代理进行代码覆盖率报告,并使用ant,它显示构建是成功的,但jacoco.exec只有1kb大小,在编译时得到错误,这就是为什么我们在build.xml中注释掉了它,我们也得到了上面的错误。

我的build.xml看起来像这样:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>

<!-- 
   Copyright (c) 2009, 2016 Mountainminds GmbH & Co. KG and Contributors
   All rights reserved. This program and the accompanying materials
   are made available under the terms of the Eclipse Public License v1.0
   which accompanies this distribution, and is available at
   http://www.eclipse.org/legal/epl-v10.html

   Contributors:
      Marc R. Hoffmann - initial API and implementation
-->

<project name="Example Ant Build with JaCoCo" xmlns:if="ant:if" xmlns:unless="ant:unless" default="rebuild" xmlns:jacoco="antlib:org.jacoco.ant">

    <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 file="code-coverage.properties"/>
    <property name="result.dir" location="${result.dir}" />
    <property name="src.dir" location="${src.home}" />
    <property name="result.classes.dir" location="${classes.dir}" />
    <property name="result.report.dir" location="${result.dir}/site/jacoco" />
    <property name="result.exec.file" location="${exec.path}/jacoco.exec" />

    <!-- Step 1: Import JaCoCo Ant tasks -->
    <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
        <classpath path="${jacoco.home}/lib/jacocoant.jar" />
    </taskdef>
    <!--<target name="clean" description="Builds jacoco report.">
        <delete dir="${result.dir}" />
    </target>-->

    <!--<target name="compile">
        <mkdir dir="${result.classes.dir}" />
        <javac srcdir="${src.dir}" destdir="${result.classes.dir}" debug="true" includeantruntime="false" />
    </target> -->
    <path id="classpath.test">
        <pathelement location="${jacoco.home}/lib/junit4-4.8.2.jar" />
    </path>
     <target name="test">
        <!-- Step 2: Wrap test execution with the JaCoCo coverage task -->
        <jacoco:coverage destfile="${result.exec.file}">
            <java classname="**/*.class" fork="true">
              <classpath>
            <pathelement location="${result.classes.dir}"/>
        </classpath>

            </java>
        </jacoco:coverage>
        <!-- Step 2: Wrap test execution with the JaCoCo coverage task -->

        <jacoco:coverage>
            <junit fork="true" forkmode="once">
                <test name="**/*Test" filtertrace="true"/>
                <classpath path="${result.classes.dir}"/>
            </junit>
        </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}">
                     <include name="**/*.java"/>
                    </fileset>
                </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="test,report" />
</project>
EN

回答 1

Stack Overflow用户

发布于 2016-09-30 20:10:05

<java classname="xxx">部分告诉JaCoCo实际运行您的应用程序。所以需要是包含main方法的类:而不仅仅是**/*.class。它不接受那里的通配符。

有关示例,请参阅http://www.eclemma.org/jacoco/trunk/doc/ant.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39790395

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档