我正在尝试使用jacoco与maven。当我运行mvn clean测试时,我期望覆盖率输出被写入目标/覆盖率报告,但是当我在构建后打开index.html时,它是空的。
我检查了以下内容:-雅可可。Exec文件是存在的,它有一堆类的名称在它-在覆盖html有一个链接"会话",当我点击它,我看到一堆如果我的类似乎已经执行当我运行maven命令
时,我没有看到任何错误或警告我不明白为什么报告是空的。从我看到的所有例子来看,这似乎应该是可行的。我错过了什么?我为maven插件使用了以下jacoco配置
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<append>true</append>
<skip>false</skip>
<excludes/>
<outputDirectory>${project.build.directory}/coverage-reports/</outputDirectory>
<dataFile>${project.build.directory}/jacoco.exec</dataFile>
<includes>
<include>mypackage.*</include>
</includes>
<check>false</check>
</configuration>
<executions>
<execution>
<id>pre-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-test</id>
<goals>
<goal>report</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
</plugin>
更新显然这与我提供的include模式有关。当我删除包含时,它确实显示了我的覆盖范围,但超出了我的需要。我仍在试图找出使用的模式来做一个适当的包括。
你还需要将它挂钩到surefire,将其更改为
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.3.201306030806</version>
<executions>
<!-- pre-unit-test execution helps setting up some maven property,
which will be used later by JaCoCo -->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<!-- passing property which will contains settings for JaCoCo agent.
If not specified, then "argLine" would be used for "jar" packaging -->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!-- report phase setup -->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- output file with report data. -->
<dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
<!-- output directory for the reports. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<argLine>${surefireArgLine}</argLine>
</configuration>
</execution>
</executions>
<configuration>
<argLine>-XX:MaxPermSize=512m</argLine>
</configuration>
</plugin>
</plugins>
</build>