来自 ant build.xml 文件的 jmockit 覆盖率报告步骤

jmockit coverage report steps from ant build.xml file

我想从 ant build.xml 文件生成 jmockit 覆盖率报告,我尝试了以下解决方案,但我没有成功。

Combined test coverage report with jMockit

Jmockit is not merging two coverage.ser files generated using coverage-output=serial

你能告诉我如何使用我可以从 ant build.xml 目标生成 jmockit 覆盖率报告吗?

我的 build.xml 文件如下所示:

<target name="tests" depends="testscompile,mkdirtests_clean,mkdirtests">
   <junit fork="yes"  forkmode="once" haltonfailure="no"  printsummary="yes" >
    <jvmarg value="-javaagent:../JUnitlib/jmockit.jar"/> 

    <sysproperty key="jmockit-coverage-output" value="serial-append"/>
    <sysproperty key="jmockit-coverage-outputDir" value="D:/report"/>
    <sysproperty key="jmockit-coverage-srcDirs" value="${src}"/>
    <sysproperty key="jmockit-coverage-metrics" value="all"/>


    <classpath>
            <pathelement location="${classes}" />     
               <fileset dir="../JUnitlib/">
                  <include name="**/*.jar"/>
               </fileset>   
               <fileset dir="../WebContent/WEB-INF/lib">
                  <include name="**/*.jar"/>
               </fileset> 
               <fileset dir="${tomcat.root}">
                  <include name="lib/log4j-1.2.17.jar"/>
                </fileset>
            </classpath>
    <batchtest>
       <fileset dir="${classes}">
          <include name="**/*Test.class" />
       </fileset>
    </batchtest>


   </junit>
   <java fork="yes" dir="D:/report" jar="../JUnitlib/jmockit-coverage.jar">
           <arg line="-Djmockit-coverage-output=html D:/report"/>

    </java>
</target>

它给我下面的错误:

java.lang.IllegalArgumentException: No class with name "org.apache.catalina.connector.ClientAbortException" found
[junit]     at mockit.internal.util.ClassLoad.loadClass(ClassLoad.java:57)
[junit]     at mockit.internal.util.ClassLoad.loadByInternalName(ClassLoad.java:31)
[junit]     at mockit.internal.util.ClassLoad.getSuperClass(ClassLoad.java:146)
[junit]     at mockit.internal.util.ClassLoad.actualSuperClass(ClassLoad.java:177)
[junit]     at mockit.internal.util.ClassLoad.whichIsSuperClass(ClassLoad.java:167)
[junit]     at mockit.external.asm.ClassWriter.getCommonSuperClass(ClassWriter.java:1694)
[junit]     at mockit.external.asm.ClassWriter.getMergedType(ClassWriter.java:1661)
[junit]     at mockit.external.asm.Frame.merge(Frame.java:1426)
[junit]     at mockit.external.asm.Frame.merge(Frame.java:1325)
[junit]     at mockit.external.asm.MethodWriter.visitMaxs(MethodWriter.java:1475)
[junit]     at mockit.external.asm.MethodVisitor.visitMaxs(MethodVisitor.java:804)
[junit]     at mockit.external.asm.ClassReader.readCode(ClassReader.java:1554)
[junit]     at mockit.external.asm.ClassReader.readMethod(ClassReader.java:1017)
[junit]     at mockit.external.asm.ClassReader.accept(ClassReader.java:693)
[junit]     at mockit.external.asm.ClassReader.accept(ClassReader.java:506)
[junit]     at mockit.coverage.modification.ClassModification.modifyClassForCoverage(ClassModification.java:142)
[junit]     at mockit.coverage.modification.ClassModification.modifyClassForCoverage(ClassModification.java:217)
[junit]     at mockit.coverage.modification.ClassModification.modifyClass(ClassModification.java:192)
[junit]     at mockit.coverage.CodeCoverage.transform(CodeCoverage.java:127)
[junit]     at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
[junit]     at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
[junit]     at java.lang.ClassLoader.defineClass1(Native Method)
[junit]     at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
[junit]     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[junit]     at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
[junit]     at java.net.URLClassLoader.access0(URLClassLoader.java:73)
[junit]     at java.net.URLClassLoader.run(URLClassLoader.java:368)
[junit]     at java.net.URLClassLoader.run(URLClassLoader.java:362)
[junit]     at java.security.AccessController.doPrivileged(Native Method)
[junit]     at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
[junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[junit]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
[junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[junit]     at java.lang.Class.forName0(Native Method)
[junit]     at java.lang.Class.forName(Class.java:348)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadClass(ClassesNotLoaded.java:70)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClass(ClassesNotLoaded.java:62)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClasses(ClassesNotLoaded.java:47)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClasses(ClassesNotLoaded.java:44)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClasses(ClassesNotLoaded.java:44)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClasses(ClassesNotLoaded.java:44)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClasses(ClassesNotLoaded.java:44)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClasses(ClassesNotLoaded.java:44)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClasses(ClassesNotLoaded.java:44)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.gatherCoverageData(ClassesNotLoaded.java:32)
[junit]     at mockit.coverage.OutputFileGenerator.generate(OutputFileGenerator.java:82)
[junit]     at mockit.coverage.CodeCoverage.run(CodeCoverage.java:80)
[junit] java.lang.IllegalArgumentException: No class with name "org.apache.catalina.connector.ClientAbortException" found
[junit]     at mockit.internal.util.ClassLoad.loadClass(ClassLoad.java:57)
[junit]     at mockit.internal.util.ClassLoad.loadByInternalName(ClassLoad.java:31)
[junit]     at mockit.internal.util.ClassLoad.getSuperClass(ClassLoad.java:146)
[junit]     at mockit.internal.util.ClassLoad.actualSuperClass(ClassLoad.java:177)
[junit]     at mockit.internal.util.ClassLoad.whichIsSuperClass(ClassLoad.java:161)
[junit]     at mockit.external.asm.ClassWriter.getCommonSuperClass(ClassWriter.java:1694)
[junit]     at mockit.external.asm.ClassWriter.getMergedType(ClassWriter.java:1661)
[junit]     at mockit.external.asm.Frame.merge(Frame.java:1426)
[junit]     at mockit.external.asm.Frame.merge(Frame.java:1325)
[junit]     at mockit.external.asm.MethodWriter.visitMaxs(MethodWriter.java:1475)
[junit]     at mockit.external.asm.MethodVisitor.visitMaxs(MethodVisitor.java:804)
[junit]     at mockit.external.asm.ClassReader.readCode(ClassReader.java:1554)
[junit]     at mockit.external.asm.ClassReader.readMethod(ClassReader.java:1017)
[junit]     at mockit.external.asm.ClassReader.accept(ClassReader.java:693)
[junit]     at mockit.external.asm.ClassReader.accept(ClassReader.java:506)
[junit]     at mockit.coverage.modification.ClassModification.modifyClassForCoverage(ClassModification.java:142)
[junit]     at mockit.coverage.modification.ClassModification.modifyClassForCoverage(ClassModification.java:217)
[junit]     at mockit.coverage.modification.ClassModification.modifyClass(ClassModification.java:192)
[junit]     at mockit.coverage.CodeCoverage.transform(CodeCoverage.java:127)
[junit]     at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
[junit]     at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
[junit]     at java.lang.ClassLoader.defineClass1(Native Method)
[junit]     at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
[junit]     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[junit]     at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
[junit]     at java.net.URLClassLoader.access0(URLClassLoader.java:73)
[junit]     at java.net.URLClassLoader.run(URLClassLoader.java:368)
[junit]     at java.net.URLClassLoader.run(URLClassLoader.java:362)
[junit]     at java.security.AccessController.doPrivileged(Native Method)
[junit]     at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
[junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[junit]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
[junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[junit]     at java.lang.Class.forName0(Native Method)
[junit]     at java.lang.Class.forName(Class.java:348)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadClass(ClassesNotLoaded.java:70)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClass(ClassesNotLoaded.java:62)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClasses(ClassesNotLoaded.java:47)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClasses(ClassesNotLoaded.java:44)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClasses(ClassesNotLoaded.java:44)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClasses(ClassesNotLoaded.java:44)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClasses(ClassesNotLoaded.java:44)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.gatherCoverageData(ClassesNotLoaded.java:32)
[junit]     at mockit.coverage.OutputFileGenerator.generate(OutputFileGenerator.java:82)
[junit]     at mockit.coverage.CodeCoverage.run(CodeCoverage.java:80)
[junit] java.lang.IllegalArgumentException: No class with name "org.apache.catalina.connector.ClientAbortException" found
[junit]     at mockit.internal.util.ClassLoad.loadClass(ClassLoad.java:57)
[junit]     at mockit.internal.util.ClassLoad.loadByInternalName(ClassLoad.java:31)
[junit]     at mockit.internal.util.ClassLoad.getSuperClass(ClassLoad.java:146)
[junit]     at mockit.internal.util.ClassLoad.actualSuperClass(ClassLoad.java:177)
[junit]     at mockit.internal.util.ClassLoad.whichIsSuperClass(ClassLoad.java:161)
[junit]     at mockit.external.asm.ClassWriter.getCommonSuperClass(ClassWriter.java:1694)
[junit]     at mockit.external.asm.ClassWriter.getMergedType(ClassWriter.java:1661)
[junit]     at mockit.external.asm.Frame.merge(Frame.java:1426)
[junit]     at mockit.external.asm.Frame.merge(Frame.java:1325)
[junit]     at mockit.external.asm.MethodWriter.visitMaxs(MethodWriter.java:1475)
[junit]     at mockit.external.asm.MethodVisitor.visitMaxs(MethodVisitor.java:804)
[junit]     at mockit.external.asm.ClassReader.readCode(ClassReader.java:1554)
[junit]     at mockit.external.asm.ClassReader.readMethod(ClassReader.java:1017)
[junit]     at mockit.external.asm.ClassReader.accept(ClassReader.java:693)
[junit]     at mockit.external.asm.ClassReader.accept(ClassReader.java:506)
[junit]     at mockit.coverage.modification.ClassModification.modifyClassForCoverage(ClassModification.java:142)
[junit]     at mockit.coverage.modification.ClassModification.modifyClassForCoverage(ClassModification.java:217)
[junit]     at mockit.coverage.modification.ClassModification.modifyClass(ClassModification.java:192)
[junit]     at mockit.coverage.CodeCoverage.transform(CodeCoverage.java:127)
[junit]     at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
[junit]     at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
[junit]     at java.lang.ClassLoader.defineClass1(Native Method)
[junit]     at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
[junit]     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[junit]     at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
[junit]     at java.net.URLClassLoader.access0(URLClassLoader.java:73)
[junit]     at java.net.URLClassLoader.run(URLClassLoader.java:368)
[junit]     at java.net.URLClassLoader.run(URLClassLoader.java:362)
[junit]     at java.security.AccessController.doPrivileged(Native Method)
[junit]     at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
[junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[junit]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
[junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[junit]     at java.lang.Class.forName0(Native Method)
[junit]     at java.lang.Class.forName(Class.java:348)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadClass(ClassesNotLoaded.java:70)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClass(ClassesNotLoaded.java:62)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClasses(ClassesNotLoaded.java:47)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClasses(ClassesNotLoaded.java:44)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClasses(ClassesNotLoaded.java:44)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClasses(ClassesNotLoaded.java:44)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.loadAdditionalClasses(ClassesNotLoaded.java:44)
[junit]     at mockit.coverage.modification.ClassesNotLoaded.gatherCoverageData(ClassesNotLoaded.java:32)
[junit]     at mockit.coverage.OutputFileGenerator.generate(OutputFileGenerator.java:82)
[junit]     at mockit.coverage.CodeCoverage.run(CodeCoverage.java:80)
[junit] java.lang.IllegalArgumentException: No class with name "com.microsoft.sqlserver.jdbc.SQLServerException" found

我认为它给了我错误,因为 jmockit 覆盖 jar 文件不正确 load.can 请你指导我关于这个...

更改您在 Generating an aggregate report from multiple data files

中指定的参数
<java fork="yes" dir="D:/report" jar="../JUnitlib/jmockit-coverage.jar">
   <jvmarg line="-Djmockit-coverage-output=html/>
   <arg line="-Dcoverage-output=html Dir1 Dir2"/>
</java>

来自 Dir1 和 Dir2 的 SER 文件将被合并,最终输出将在 D:/report

如果 line 出现错误,<arg line="-Dcoverage-output=html Dir1 Dir2"/> 也尝试删除 -Dcoverage-output=html。如果错误仍然存​​在,请尝试为 jar= 提供绝对路径。