我正在嘗試獲取集成測試的代碼覆蓋率報告。 Jacoco maven插件能夠爲單元測試提供代碼覆蓋率,但是爲集成測試提供0%的覆蓋率。集成測試正在部署在tomcat中的應用程序的終點。Jacoco Maven離線設備 - Tomcat
我的maven jacoco插件& surefire插件看起來像這樣。
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>prepare-agent-integration</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/target/jacoco-it.exec</dataFile>
<outputDirectory>${project.build.directory}/target/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<!-- <skip>true</skip> -->
<!-- <systemPropertyVariables> <jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables> -->
</configuration>
<!-- <configuration> <skip>true</skip> </configuration> -->
<executions>
<execution>
<id>unit-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<!-- Never skip running the tests when the test phase is invoked -->
<!-- <skip>true</skip> -->
<argLine>@{argLine}
-javaagent:c:\\iat\\mavenrepository\\org\\jacoco\\org.jacoco.agent\\0.7.10-SNAPSHOT\\org.jacoco.agent-0.7.10-SNAPSHOT-runtime.jar=destfile=C:\\Users\\dmahapat\\Workspaces\\MyEclipse
2016 CI\\JaxRsApp\\target\\jacoco.exec</argLine>
<includes>
<include>**/*UnitTest.java</include>
</includes>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<!-- Never skip running the tests when the integration-test phase
is invoked -->
<!-- argLine>-javaagent:$WORKSPACE/target/lib/jacoco-agent-0.7.9.jar=includes=*,destfile=*/jacoco-coverage.exec,append=false</argLine -->
<skip>false</skip>
<argLine>@{argLine}
-javaagent:c:\\iat\\mavenrepository\\org\\jacoco\\org.jacoco.agent\\0.7.10-SNAPSHOT\\org.jacoco.agent-0.7.10-SNAPSHOT-runtime.jar=destfile=C:\\Users\\dmahapat\\Workspaces\\MyEclipse
2016 CI\\JaxRsApp\\target\\jacoco-it.exec
</argLine>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
<excludes>
<exclude>**/*UnitTest.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
我執行單元測試,在測試階段中集成測試階段&集成測試。 我得到的最新錯誤是「由於缺少執行數據文件而跳過JaCoCo執行程序」。
我是否需要提供以下參數-javaagent啓動Tomcat:C:\\ \\ IAT \\ mavenrepository組織\\ \\ jacoco組織。 jacoco.agent \\ 0.7.10-SNAPSHOT \\ org.jacoco.agent-0.7.10-SNAPSHOT-runtime.jar = destfile = C:\\ Users \\ dmahapat \\ Workspaces \\ MyEclipse2016 CI \\ JaxRsApp \\ target \\ jacoco-it.exec –
如果您使用Maven啓動Tomcat,那麼'jacoco-maven-plugin'爲您準備好這個參數,所以您只需要像平常一樣將它傳遞給Tomcat Maven屬性 - '$ {argLine}'。 – Godin
@debajyotimahapatro請不要忘記upvote有幫助,並接受+ upvote正確的答案,成爲本網站的好用戶。 – Godin