我已经切换到最新的JDK 7,我在使用emma覆盖工具打字的字节代码上运行testng单元测试时遇到问题。我的测试用例都没有正确运行,对于大多数测试用例我都收到了这样的错误。
java.lang.ClassFormatError: Illegal local variable table length 10 in method measurement.meter.AbstractSerialPortMeter.<init>(Lmeasurement/meter/SerialPort;)V at measurement.meter.Elc3133aTest.setUp(Elc3133aTest.java:42)
我在这里发现了一篇文章JSR 292 Goodness Fast Code Coverage Tool Less 10k, 这就是说“JSR 292引入了一个新的字节码指令invokedynamic,但也引入了几种新的常量池常量。这意味着大多数解析字节码的工具如ASM,BCEL,findbugs或EMMA都需要更新为java 7兼容“。
查看了Emma主页,但看起来很长时间没有更新。
有人解决了类似的问题吗?
我也曾尝试过Cobertura。它看起来工作得更好但我得到了很多VerifyError
类型的例外。
java.lang.VerifyError: Expecting a stackmap frame at branch target 85 in method measurement.meter.AbstractSerialPortMeter.close()V at offset 26
at measurement.meter.AbstractSerialPortMeterTest.setUp(AbstractSerialPortMeterTest.java:27)
答案 0 :(得分:76)
我使用maven cobertura插件时遇到了同样的问题。从cobertura运行时,所有测试都失败了:报告。但是直接从surefire插件运行所有测试都成功了。正如你们中的一些人已经说过的那样,coberture字节码的检测与JDK7不兼容。
您可以在此处看到http://vikashazrati.wordpress.com/2011/10/09/quicktip-verifyerror-with-jdk-7/该异常与“具有StackMapTable属性的新类型检查器”相关(请参阅:http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html中的-X:+ UseSplitVerifier JVM选项)。
所以我的解决方案是配置surefire-plugin以始终使用JVM arg执行测试“-XX:-UseSplitVerifier。无论使用和不使用cobertura工具,都可以正常运行。
我在maven中的surefire配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<argLine>-XX:-UseSplitVerifier</argLine>
</configuration>
</plugin>
答案 1 :(得分:5)
我有同样的问题。
幸运的是beta适用于JDK 7。
更新站点链接:http://download.eclipselab.org/eclemma/beta/2.0.0/update/
此链接应在Eclipse中使用:
Help -> Install new software... -> Add...
休息应该很容易;)
答案 2 :(得分:2)
我得到Gradle 1.0M9,Java 7和EMMA 2.1使用这里建议的补丁:使用jvm参数。
configurations{
emma
}
dependencies {
// EMMS Code Coverage
emma "emma:emma:2.1.5320"
emma "emma:emma_ant:2.1.5320"
...
testCompile group: 'junit', name: 'junit', version: '4.9'
}
test {
// add EMMA related JVM args to our tests
jvmArgs "-XX:-UseSplitVerifier", "-Demma.coverage.out.file=$buildDir/tmp/emma/metadata.emma", "-Demma.coverage.out.merge=true"
doFirst {
println "Instrumenting the classes at " + sourceSets.main.output.classesDir.absolutePath
// define the custom EMMA ant tasks
ant.taskdef( resource:"emma_ant.properties", classpath: configurations.emma.asPath)
ant.path(id:"run.classpath") {
pathelement(location:sourceSets.main.output.classesDir.absolutePath)
}
def emmaInstDir = new File(sourceSets.main.output.classesDir.parentFile.parentFile, "tmp/emma/instr")
emmaInstDir.mkdirs()
println "Creating $emmaInstDir to instrument from " + sourceSets.main.output.classesDir.absolutePath
// instruct our compiled classes and store them at $buildDir/tmp/emma/instr
ant.emma(enabled: 'true', verbosity:'info'){
instr(merge:"true", destdir: emmaInstDir.absolutePath, instrpathref:"run.classpath",
metadatafile: new File(emmaInstDir, '/metadata.emma').absolutePath) {
instrpath {
fileset(dir:sourceSets.main.output.classesDir.absolutePath, includes:"**/*.class")
}
}
}
setClasspath(files("$buildDir/tmp/emma/instr") + configurations.emma + getClasspath())
}
// The report should be generated directly after the tests are done.
// We create three types (txt, html, xml) of reports here. Running your build script now should
// result in output like that:
doLast {
def srcDir = sourceSets.main.java.srcDirs.toArray()[0]
println "Creating test coverage reports for classes " + srcDir
def emmaInstDir = new File(sourceSets.main.output.classesDir.parentFile.parentFile, "tmp/emma")
ant.emma(enabled:"true"){
new File("$buildDir/reports/emma").mkdirs()
report(sourcepath: srcDir){
fileset(dir: emmaInstDir.absolutePath){
include(name:"**/*.emma")
}
txt(outfile:"$buildDir/reports/emma/coverage.txt")
html(outfile:"$buildDir/reports/emma/coverage.html")
xml(outfile:"$buildDir/reports/emma/coverage.xml")
}
}
println "Test coverage reports available at $buildDir/reports/emma."
println "txt: $buildDir/reports/emma/coverage.txt"
println "Test $buildDir/reports/emma/coverage.html"
println "Test $buildDir/reports/emma/coverage.xml"
}
}
运行“gradle test”给出以下内容:
marcello@hawaii:/u1/development/workspaces/open-source/interviews/vmware$ gradle test
:compileJava
:processResources UP-TO-DATE
:classes
:compileTestJava
:processTestResources UP-TO-DATE
:testClasses
:test
Instrumenting the classes at /u1/development/workspaces/open-source/interviews/vmware/build/classes/main
Creating /u1/development/workspaces/open-source/interviews/vmware/build/tmp/emma/instr to instrument from /u1/development/workspaces/open-source/interviews/vmware/build/classes/main
Creating test coverage reports for classes /u1/development/workspaces/open-source/interviews/vmware/src/main/java
Test coverage reports available at /u1/development/workspaces/open-source/interviews/vmware/build/reports/emma.
txt: /u1/development/workspaces/open-source/interviews/vmware/build/reports/emma/coverage.txt
Test /u1/development/workspaces/open-source/interviews/vmware/build/reports/emma/coverage.html
Test /u1/development/workspaces/open-source/interviews/vmware/build/reports/emma/coverage.xml
BUILD SUCCESSFUL
答案 3 :(得分:1)
如果您不使用新语言功能(如try-with-resources等),Emma可以正常工作。您可以使用新的库(Paths,DirectoryStream等)来使用Java 7。 我知道这不是你问题的解决方案,但是如果你只想检查“JDK 7如何执行”它可能有用......
答案 4 :(得分:1)
我遇到了这个问题。使用Eclipse市场升级到2.0.1.201112281951对我有用。
答案 5 :(得分:1)
IntelliJ IDEA 11的内部覆盖工具适用于我的项目使用try-with-resources,diamond运算符,但我们没有使用invokedynamic。我认为社区版不包括覆盖工具,仅限终极版。
我还没有尝试过jacoco - 大多数emma的前开发者似乎已经离开了。
答案 6 :(得分:0)
Pedro Ballesteros给出的Java 8+等效答案是:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<argLine>-noverify</argLine>
</configuration>
</plugin>
(调整版本号以匹配您正在使用的Surefire的版本。)