Java 为什么Jacoco会显示代码覆盖率为0?
下面是pom.xmlJava 为什么Jacoco会显示代码覆盖率为0?,java,maven,code-coverage,jacoco,Java,Maven,Code Coverage,Jacoco,下面是pom.xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18</version> <configuration>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version>
<configuration>
<!-- Sets the VM argument line used when unit tests are run. -->
<argLine>-Xms512m -Xmx1024m -XX:MaxPermSize=512m ${jacoco.agent.argLine}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<dataFile>target/jacoco.exec</dataFile>
</configuration>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jacoco.agent.argLine</propertyName>
<destFile>target/jacoco.exec</destFile>
</configuration>
</execution>
<execution>
<id>default-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
更新
正在添加另一个maven日志。。。这是在测试用例运行之后
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ app-core ---
[INFO] Building jar: C:\Users\SHANK030\git\AdaptivePaymentPlatform\APP_Core\target\appCore.jar
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.5.201505241946:report (default-report) @ app-core ---
[INFO] Analyzed bundle 'Adaptive Payment Platrom Core' with 68 classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:08 min
[INFO] Finished at: 2015-06-04T15:28:28-05:00
[INFO] Final Memory: 51M/594M
[INFO] ------------------------------------------------------------------------
将jacoco插件配置更改为
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<dataFile>target/jacoco.exec</dataFile>
</configuration>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jacoco.agent.argLine</propertyName>
<destFile>target/jacoco.exec</destFile>
</configuration>
</execution>
<execution>
<id>default-report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
org.jacoco
jacocomaven插件
0.7.5.201505241946
target/jacoco.exec
单元前测试
配制剂
jacoco.agent.argLine
target/jacoco.exec
默认报告
验证
报告
然后调用mvn验证
同时检查maven的输出,它将提示您是否在测试中执行了jacoco。我在应用程序中使用了powermock,但它与jacoco执行的在线检测不兼容。因此,使用离线插装并排除一些clousure类对我来说是有效的 我正在使用mvn clean verify install运行该作业,下面是我的pom的更改片段
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
<forkMode>once</forkMode>
<argLine>-Xms1024m -Xmx2048m -XX:MaxPermSize=1024m</argLine>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>**/StratusAuthTemplateProviderTest.class</exclude>
<exclude>**/StratusBalanceInquiryTemplateProviderTest.class</exclude>
<exclude>**/PersistCardAuthDetailsForRefundProcessorTest.class</exclude>
<exclude>**/PersistCardTxnDetailsProcessorTest.class</exclude>
<exclude>**/StratusAuthProcessorTest.class</exclude>
<exclude>**/UpdateTxnStatusTest.class</exclude>
<exclude>**/RulesTest.class</exclude>
<exclude>**/SampleRulesTest.class</exclude>
<exclude>**/RefundUpdatePmtTxnConfirmationProcessorTest.class</exclude>
<exclude>**/vo/*.class</exclude>
<exclude>**/outbound/*.class</exclude>
<exclude>**/notification/*.class</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.4.201502262128</version>
<configuration>
<excludes>
<exclude>com/wdpr/payment/data/mapper/*.class</exclude>
<exclude>**/*AjcClosure?.class</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>METHOD</element>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
org.apache.maven.plugins
maven surefire插件
2.18
默认测试
测试
测试
target/jacoco.exec
一旦
-Xms1024m-Xmx2048m-XX:MaxPermSize=1024m
META-INF/*.SF
**/StratusAuthTemplateProviderTest.class
**/StratusBalanceInquiryTemplateProviderTest.class
**/PersistCardAuthDetailsForefundProcessorTest.class
**/PersistCardTxnDetailsProcessorTest.class
**/StratusAuthProcessorTest.class
**/UpdateTxnStatusTest.class
**/规则类
**/最高级
**/ReturnUpdatePmttxnConfirmationProcessorTest.class
**/vo/*.类
**/出站/*.class
**/通知/*.class
org.jacoco
jacocomaven插件
0.7.4.201502262128
com/wdpr/payment/data/mapper/*.class
**/*AjcClosure?类
默认工具
仪器
默认还原检测类
恢复插入指令的类
默认报告
准备包装
报告
默认检查
检查
方法
运行mvn测试
或mvn验证
。您已经绑定了jacoco:report
到测试阶段,它应该绑定到verify
谢谢您的评论,但我有点困惑。。。请您详细说明一下。根据您的建议进行了更改,并从eclipse以干净的方式运行验证仍然存在相同的问题。我已经添加了maven日志供您参考。执行prepare-agent(预单元测试)。在测试执行之后,如果你发现了一些关于jacoco的信息,你能查看日志吗?添加了同一个maven运行的最后一部分。。。你能查一下吗
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
<forkMode>once</forkMode>
<argLine>-Xms1024m -Xmx2048m -XX:MaxPermSize=1024m</argLine>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>**/StratusAuthTemplateProviderTest.class</exclude>
<exclude>**/StratusBalanceInquiryTemplateProviderTest.class</exclude>
<exclude>**/PersistCardAuthDetailsForRefundProcessorTest.class</exclude>
<exclude>**/PersistCardTxnDetailsProcessorTest.class</exclude>
<exclude>**/StratusAuthProcessorTest.class</exclude>
<exclude>**/UpdateTxnStatusTest.class</exclude>
<exclude>**/RulesTest.class</exclude>
<exclude>**/SampleRulesTest.class</exclude>
<exclude>**/RefundUpdatePmtTxnConfirmationProcessorTest.class</exclude>
<exclude>**/vo/*.class</exclude>
<exclude>**/outbound/*.class</exclude>
<exclude>**/notification/*.class</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.4.201502262128</version>
<configuration>
<excludes>
<exclude>com/wdpr/payment/data/mapper/*.class</exclude>
<exclude>**/*AjcClosure?.class</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>METHOD</element>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>