首页 文章

Testng,Emma,Cobertura,coverage和JDK 7导致ClassFormatError和VerifyError

提问于
浏览
55

我已经切换到最新的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 introduces a new bytecode instruction invokedynamic but also several new kind of constant pool constants. Which means that most of the tools that parse bytecodes like ASM, BCEL, findbugs or EMMA will need to be updated to be java 7 compatible."

检查了艾玛的主页,但看起来它已经很久没有更新了 .

有人解决了类似的问题吗?

我也曾尝试过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)

6 回答

  • 1

    我遇到过同样的问题 . 幸运的是beta适用于JDK 7 .
    更新站点链接:http://download.eclipselab.org/eclemma/beta/2.0.0/update/
    此链接应在Eclipse中使用:

    Help -> Install new software... -> Add...
    

    休息应该很容易;)

  • 5

    我使用maven cobertura插件时遇到了同样的问题 . 从cobertura运行时,所有测试都失败了:报告 . 但是直接从surefire插件运行所有测试都成功了 . 正如你们中的一些人已经说过的那样,coberture字节码的检测与JDK7不兼容 .

    您可以在此处看到http://vikashazrati.wordpress.com/2011/10/09/quicktip-verifyerror-with-jdk-7/该异常与"new type checker with StackMapTable attributes"相关(请参阅:_X884444_中的-X:UseSplitVerifier JVM选项) .

    所以我的解决方案是配置surefire-plugin以始终使用JVM arg“-XX:-UseSplitVerifier执行测试 . 无论使用和不使用cobertura工具,它都可以正常工作 .

    我在maven中的万无一失的配置:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12</version>
        <configuration>
            <argLine>-XX:-UseSplitVerifier</argLine>
        </configuration>
    </plugin>
    
  • 1

    我得到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"
        }
    }
    

    运行“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
    
  • 76

    如果您不使用新的语言功能(如try-with-resources等),Emma可以正常工作 . 您可以使用新的库(Paths,DirectoryStream等)来使用Java 7 . 我知道这不是你问题的解决方案,但是如果你只想检查“JDK 7如何执行”它可能会起作用......

  • 2

    我遇到了这个问题 . 使用Eclipse市场升级到2.0.1.201112281951对我有用 .

  • 1

    IntelliJ IDEA 11的内部覆盖工具适用于我的项目使用try-with-resources,diamond运算符但我们没有使用invokedynamic . 我认为社区版不包含覆盖工具,仅限终极版 .

    我还没有尝试过jacoco - 这是大多数艾玛的前开发者似乎已经离开的地方 .

相关问题