Jacoco代码覆盖率在Tomcat:jdk7+;梯度1.5+;Jacoco 0.6.2+;Tomcat 7.0.29

Jacoco代码覆盖率在Tomcat:jdk7+;梯度1.5+;Jacoco 0.6.2+;Tomcat 7.0.29,tomcat,gradle,jacoco,Tomcat,Gradle,Jacoco,我有以下环境:jdk7+gradle1.5+jacoco0.6.2+tomcat7.0.29(我的要点是完整的代码) 下面的build.gradle是我当前的构建脚本,我试图从中运行以Rest-Assured为Restful API编写的集成测试的代码覆盖率。我尝试过Jacoco插件(org.ajoberstar:gradle Jacoco:0.3.0),我尝试过从jar中使用Jacoco,并尝试过使用代理,但它甚至没有启动() 在尝试使用该插件之后,我决定从Jars手动运行Jacoco。完整的

我有以下环境:jdk7+gradle1.5+jacoco0.6.2+tomcat7.0.29(我的要点是完整的代码)

下面的build.gradle是我当前的构建脚本,我试图从中运行以Rest-Assured为Restful API编写的集成测试的代码覆盖率。我尝试过Jacoco插件(org.ajoberstar:gradle Jacoco:0.3.0),我尝试过从jar中使用Jacoco,并尝试过使用代理,但它甚至没有启动()

在尝试使用该插件之后,我决定从Jars手动运行Jacoco。完整的应用程序可在下载。下面是脚本片段,其中更改为添加Jvm选项以添加Jvm选项:

task integrationTest(type: Test, dependsOn: jar, description: 'Runs the integration tests.', group: 'verification') {
  testClassesDir = sourceSets.integrationTest.output.classesDir
  classpath = sourceSets.integrationTest.runtimeClasspath
  systemProperties['jar.path'] = jar.archivePath

  // use JaCoCo agent to record execution coverage data
  jvmArgs "-javaagent:$configurations.jacoco.asPath=destfile=$buildDir/jacoco-int.exec"
}
check.dependsOn integrationTest

integrationTest.doFirst {
  println 'Starting the embedded tomcat server'
  tasks.tomcatRun.daemon = true
  tasks.tomcatRun.execute()
}

integrationTest.doLast {
  println 'Stopping the embedded tomcat server'
  tasks.tomcatStop.execute()
}

在示例代码中,您将构建脚本配置为运行整型测试的覆盖率,而不是生产代码。您是要收集用于与tomcat服务器通信的API的覆盖率数据,还是要收集tomcat上运行的代码的覆盖率数据。对于后者,您必须插入在TomcatJVM中执行的代码,而不是integTest代码。因此,您必须将javaagent设置添加到“tomcatRun”任务中

希望有帮助

干杯


勒内

我将尝试检测它并运行。。。谢谢
task integrationTest(type: Test, dependsOn: jar, description: 'Runs the integration tests.', group: 'verification') {
  testClassesDir = sourceSets.integrationTest.output.classesDir
  classpath = sourceSets.integrationTest.runtimeClasspath
  systemProperties['jar.path'] = jar.archivePath

  // use JaCoCo agent to record execution coverage data
  jvmArgs "-javaagent:$configurations.jacoco.asPath=destfile=$buildDir/jacoco-int.exec"
}
check.dependsOn integrationTest

integrationTest.doFirst {
  println 'Starting the embedded tomcat server'
  tasks.tomcatRun.daemon = true
  tasks.tomcatRun.execute()
}

integrationTest.doLast {
  println 'Stopping the embedded tomcat server'
  tasks.tomcatStop.execute()
}