我想从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.access$100(URLClassLoader.java:73)
[junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
[junit] at java.net.URLClassLoader$1.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$1.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.access$100(URLClassLoader.java:73)
[junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
[junit] at java.net.URLClassLoader$1.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$1.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.access$100(URLClassLoader.java:73)
[junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
[junit] at java.net.URLClassLoader$1.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$1.run(CodeCoverage.java:80)
[junit] java.lang.IllegalArgumentException: No class with name "com.microsoft.sqlserver.jdbc.SQLServerException" found
由于jmockit coverage jar文件未正确加载,我认为它给了我错误。请您指导我一下...
最佳答案
更改您在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
如果您在第
<arg line="-Dcoverage-output=html Dir1 Dir2"/>
行出现错误,请尝试也删除-Dcoverage-output = html。如果错误仍然存在,请尝试为jar=
提供绝对路径。关于java - jmockit覆盖率报告步骤来自ant build.xml文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34395725/