java emma 官网_Java 7-Testng,Emma,Cobertura,coverage和JDK 7导致ClassFormatError和VerifyE

博客介绍了使用Gradle 1.0M9、Java 7和EMMA 2.1进行代码测试覆盖的方法,给出了配置代码,包括依赖配置、JVM参数设置等,还展示了如何生成测试覆盖报告,运行“gradle test”可得到相关信息并成功构建。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

}

}

运行“等级测试”可得到以下信息:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值