为你的maven项目加上测试覆盖率报告。

本文介绍如何使用Maven Clover2插件进行代码覆盖率分析。通过在pom.xml文件中配置Clover2插件,可以指定代码覆盖率目标、排除文件、报告生成等设置,并通过mvn命令执行代码覆盖率检查。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里使用[url=http://docs.atlassian.com/maven-clover2-plugin/2.3.1/]maven clover plugin[/url], 在你的pom.xml中加上以下的代码。

<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>

<configuration>
<!--includesTestSourceRoots>false</includesTestSourceRoots-->
<targetPercentage>1%</targetPercentage>

<!-- Verify that we can specify the JDK version for Clover's instrumentation -->
<jdk>1.6</jdk>

<!-- Verify that we can exclude some files from the instrumentation. Make sure the file we are excluding
is referenced by other classes to ensure excluding is only done at the Clover level -->
<excludes>

<exclude>**/*Dummy*.java</exclude>
</excludes>

<licenseLocation>${clover.licenseLocation}</licenseLocation>
</configuration>
<executions>
<execution>
<id>main</id>

<phase>verify</phase>
<goals>
<goal>instrument</goal>
<goal>check</goal>
</goals>
</execution>
<execution>

<id>site</id>
<phase>pre-site</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
</executions>

</plugin>


  <reporting>
<excludeDefaults>true</excludeDefaults>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>

<artifactId>maven-clover2-plugin</artifactId>
<configuration>

<!-- Verify that we can modify the location of the Clover database and that the directory is created if
it doesn't exist. Note: we're putting the configuration here and not in the build section because the
build section inherits from the reporting section but not the other way around... -->
<!--cloverDatabase>${project.build.directory}/customclover/myclover.db</cloverDatabase-->

<!-- Verify that we can generate all types of Clover reports -->
<generateHtml>true</generateHtml>
<generatePdf>true</generatePdf>

<generateXml>true</generateXml>

<!-- We ask the Clover plugin to generate a historical report but we don't have any historical data saved.
This is to verify it doesn't error out when this is the case. -->
<generateHistorical>true</generateHistorical>
<licenseLocation>${clover.licenseLocation}</licenseLocation>
<!--useFullyQualifiedJavaLang>false</useFullyQualifiedJavaLang-->
</configuration>
</plugin>

</plugins>
</reporting>


然后运行 mvn install 和 mvn site 就行了。 当然其中会有一些这个maven插件的配置。 具体请看http://docs.atlassian.com/maven-clover2-plugin/2.3.1/usage.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值