Testng,Emma,Cobertura,覆盖率和JDK 7导致ClassFormatError和VerifyError
我已经切换到最新的JDK 7,并且我正在对由emma覆盖工具弄乱的字节码进行testngunit testing。 我的testing用例都没有正确运行,而且其中大部分我都收到这样的错误。
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)
我在这里find了一篇文章JSR 292 Goodness Fast Code Coverage Toolless于10k ,这就是说“JSR 292引入了一个新的字节码指令invokedynamic,而且还有一些新的常量池常量,这意味着大多数parsing字节码的工具就像ASM,BCEL,findbugs或EMMA将需要更新为Java 7兼容。“
检查了Emma主页,但看起来好像很久没有更新了。
有没有人解决过类似的问题?
我也尝试过Cobertura。 它看起来更好一些,但是我得到了许多typesVerifyError
的exception。
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)
我遇到过同样的问题。 幸运的是,testing版与JDK 7一起使用。
更新网站链接: http : //download.eclipselab.org/eclemma/beta/2.0.0/update/
这个链接应该在Eclipse中使用:
Help -> Install new software... -> Add...
rest应该很容易;)
我有同样的问题,使用maven cobertura插件。 从cobertura:report运行所有testing失败。 但是直接从surefire插件运行,所有的testing都成功了。 正如你们中的一些人所说的那样,问题在于coberture字节码检测与JDK7不兼容。
你可以在这里看到http://vikashazrati.wordpress.com/2011/10/09/quicktip-verifyerror-with-jdk-7/这个exception与“带有StackMapTable属性的新types检查器”有关(见:-X : http ://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html中的+ UseSplitVerifier JVM选项)。
所以我的解决scheme是configurationsurefire插件总是使用JVM参数“-XX:-UseSplitVerifier”来执行testing,它在使用和不使用cobertura的情况下工作良好。
在maven中我确定的configuration:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12</version> <configuration> <argLine>-XX:-UseSplitVerifier</argLine> </configuration> </plugin>
我得到了Gradle 1.0M9,Java 7和EMMA 2.1使用这里提到的补丁:使用jvm参数。
详情在这里… http://marcellodesales.wordpress.com/2012/04/03/running-emma-code-test-coverage-with-java-7-and-gradle-1-0m9/?preview=true&preview_id= 179&preview_nonce = 261e892908
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" } }
运行“gradletesting”给出以下内容:
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
如果您不使用新的语言function(如试用资源等),Emma可以工作。 您可以使用Java 7使用新的库(path,DirectoryStream等)。 我知道这不会解决您的问题,但是如果您只想检查“JDK 7如何执行”,则可能有效。
我有这个问题。 升级到2.0.1.201112281951使用Eclipse市场为我工作。
IntelliJ IDEA 11的内部覆盖工具对我的项目使用try-with-resources,钻石操作符工作正常,但是我们没有使用invokedynamic。 我认为覆盖工具不包括在社区版中,只是最终的。
我还没有尝试jacoco – 这是艾玛的大部分前开发者似乎已经走了。