有没有办法使用带有tomcat7 -maven-plugin嵌入式实例的 JaCoCo 来获得代码覆盖率?
jacoco-maven-plugin 在我的 WAR 的 POM 中配置以检测我的单元测试,但我不确定如何将 jacoco 代理附加到嵌入式 Tomcat 实例以检测针对 Tomcat 运行的集成测试。鉴于 Tomcat 实例是嵌入式的,我不确定这种方法是否可行。有没有其他方法可以做到这一点?我可能可以从使用 Tomcat Maven 插件切换到使用 Cargo 来获得覆盖,但如果可能的话,我更愿意坚持使用 Tomcat 插件。
以下是我的 POM 中的一些相关片段:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.2.201302030002</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.14</version>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<systemProperties>
<!-- as expected, this system property doesn't work since Tomcat is embedded, but this is the type of config I'm looking for -->
<JAVA_OPTS>-javaagent:${project.build.directory}/${jacoco.jar}=destfile=${project.build.directory}/jacoco.exec,append=true</JAVA_OPTS>
</systemProperties>
</configuration>
<executions>
<execution>
<id>tomcat-startup</id>
<goals>
<goal>run-war-only</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>tomcat-shutdown</id>
<goals>
<goal>shutdown</goal>
</goals>
<phase>post-integration-test</phase>
</execution>
</executions>
</plugin>
版本:Maven 3.0.4、Tomcat Maven 插件 2.1、Jacoco 0.6.2.201302030002、Java 7