Nice programing

Testng, Emma, ​​Cobertura, Coverage 및 JDK 7 결과 ClassFormatError 및 VerifyError

nicepro 2021. 1. 7. 21:21
반응형

Testng, Emma, ​​Cobertura, Coverage 및 JDK 7 결과 ClassFormatError 및 VerifyError


나는 최신 JDK 7로 전환했으며 emma coverage 도구로 가득 찬 바이트 코드에서 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)

나는 같은 문제가 있었다. 다행히 베타는 JDK 7에서 작동합니다.
업데이트 사이트 링크 : http://download.eclipselab.org/eclemma/beta/2.0.0/update/
이 링크는 Eclipse에서 사용해야합니다.

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


휴식은 쉬울 것입니다;)


maven cobertura 플러그인을 사용하여 동일한 문제가 발생했습니다. cobertura : report에서 실행할 때 모든 테스트가 실패했습니다. 그러나 모든 테스트는 surefire 플러그인에서 직접 실행했을 때 성공했습니다. 여러분 중 일부는 이미 Coberture 바이트 코드 인스 트루먼 테이션이 JDK7과 호환되지 않는다는 문제를 언급했습니다.

여기 http://vikashazrati.wordpress.com/2011/10/09/quicktip-verifyerror-with-jdk-7/ 에서 예외가 "StackMapTable 속성이있는 새 유형 검사기"와 관련되어 있음을 확인할 수 있습니다 (참조 : -X : + UseSplitVerifier JVM 옵션 ( http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html ).

그래서 내 솔루션은 JVM arg "-XX : -UseSplitVerifier로 항상 테스트를 실행하도록 surefire-plugin을 구성하는 것입니다. 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>

여기에 제안 된 패치 (jvm 인수 사용)로 작업하는 Gradle 1.0M9, Java 7 및 EMMA 2.1이 있습니다.

자세한 내용은 여기 ... 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

Emma는 새로운 언어 기능 (예 : try-with-resources)을 사용하지 않는 경우 작동합니다. 새로운 라이브러리 (Paths, DirectoryStream 등)를 사용하여 Java 7을 사용할 수 있습니다. 이것이 문제에 대한 해결책이 아니라는 것을 알고 있지만 "JDK 7의 성능"만 확인하려면 작동 할 수 있습니다.


이 문제가 발생했습니다. Eclipse 마켓 플레이스를 사용하여 2.0.1.201112281951로 업그레이드하는 것이 저에게 효과적이었습니다.


IntelliJ IDEA 11's internal coverage tool works fine for my project using try-with-resources, diamond operator but we are not using invokedynamic. I think the coverage tool is not included in the community edition, ultimate only.

I have yet to try jacoco - it's where most of emma's former developers seem to have gone.


The Java 8+ equivalent of the answer by Pedro Ballesteros is:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.12.4</version>
  <configuration>
    <argLine>-noverify</argLine>
  </configuration>
</plugin>

(Tweak the version number to match the version of Surefire you are using.)

ReferenceURL : https://stackoverflow.com/questions/7010665/testng-emma-cobertura-coverage-and-jdk-7-result-in-classformaterror-and-verif

반응형