【问题标题】:Jacoco coverage with Ant throws java.lang.instrument.IllegalClassFormatException: Error while instrumenting class使用 Ant 的 Jacoco 覆盖抛出 java.lang.instrument.IllegalClassFormatException:检测类时出错
【发布时间】:2020-12-28 16:59:40
【问题描述】:

我将 Jacoco 与我的 Ant 构建集成。当我运行构建时,测试用例成功执行,然后在我的 TEST-com.worker.ManagerTest.xml 中出现以下异常。 当我添加 excludes="*" 时,不会引发错误。但是 jacoco.exec 生成的大小为 1kb,当我运行报告时,什么也没有生成。有人可以告诉我我错过了什么吗?

例外:

下面是 jacoco 构建脚本。

<target name="test"  depends="test-compile">
    <mkdir dir="${report.dir}" />
    <jacoco:coverage destfile="${report.dir}/jacoco.exec"  xmlns:jacoco="antlib:org.jacoco.ant" exclclassloader="sun.reflect.DelegatingClassLoader:javassist.Loader">
        <junit fork="true" forkmode="once" printsummary="on">
        <classpath>
            <!--<pathelement location="${basedir}/../../../build/lib/aspectjtools.jar"/>
            <pathelement location="${basedir}/../../../build/lib/aspectjrt.jar"/>-->
            <pathelement path="${test.path}" />
            <pathelement path="${dist.dir}/test/unittest-manager.jar" />
        </classpath>
        <formatter type="xml" />
        <batchtest todir="${report.dir}"  fork="yes">
            <fileset dir="test">
                <include name="**/*Test*" />
            </fileset>
        </batchtest>
    </junit>
    </jacoco:coverage>
    </target>

<target name="report"  depends="test">
    <echo message="Generating Jacoco reports..." />
    <property name="report.dir.file" value="${report.dir}/jacoco.exec"/>
                    <jacoco:report>
                        <executiondata>
                            <file file="${report.dir.file}"/>
                        </executiondata>
                        <structure name="JaCoCo Reports">
                            <classfiles>
                                <fileset dir="${dist.dir}/applications/lib/manager.jar">
                                       <include name="**/*.class"/>
                                </fileset>
                            </classfiles>
                            <sourcefiles encoding="UTF-8">
                                <fileset dir="${src.dir}">
                                 <include name="**/*.java"/>
                                </fileset>
                            </sourcefiles>
                        </structure>
                    <html destdir="${report.dir}/coverage"/>
                    </jacoco:report>
</target>

这是我得到的空报告。

问候, 周六

【问题讨论】:

    标签: ant jacoco test-coverage


    【解决方案1】:

    我使用了最新的 0.8.7 版本,它工作正常。

    【讨论】:

    • 截至 2021 年 4 月 18 日,我没有看到 0.8.7 发布
    猜你喜欢
    • 2021-12-22
    • 2017-04-19
    • 1970-01-01
    • 2021-02-18
    • 1970-01-01
    • 2020-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多