有没有办法使用JaCoCo和tomcat7-maven-plugin嵌入式实例获取代码覆盖?
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> …
Run Code Online (Sandbox Code Playgroud)