`
dengyin2000
  • 浏览: 1232251 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

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

阅读更多
这里使用maven clover plugin, 在你的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
2
0
分享到:
评论
1 楼 dengyin2000 2008-11-06  
对资源文件需要制定编码可以使用encoding 这个参数, 如下:
.............
        <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>
          [b]<encoding>utf-8</encoding>[/b]

          <!-- 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>
.............

相关推荐

    Maven-项目管理和构建自动化工具

    Maven插件是Maven构建过程中的扩展点,提供了额外的功能,如代码生成、测试覆盖率报告等。在`pom.xml`文件中配置相应的插件,可以让Maven在构建过程中执行特定的任务。 ##### 10. Maven的多模块项目 对于大型项目...

    dependencypath-maven-plugin-1.1.1.zip

    这对于自动化构建和测试过程中的路径引用尤其有用,例如在某些场景下,我们可能需要知道特定依赖的本地路径来执行特定操作,如单元测试、代码覆盖率报告等。 该插件的版本`1.1.1`是一个稳定且经过社区验证的版本,...

    Myeclipse中的JUnit测试详细

    8. **测试覆盖率**:MyEclipse还可以集成JaCoCo等代码覆盖率工具,帮助开发者了解测试用例覆盖了多少源代码,从而改进测试的全面性。 9. **持续集成与构建工具**:在大型项目中,通常会使用Jenkins、Maven或Gradle...

    kotlin-bootstrap:适用于Kotlin的Bootstrap项目,适合分叉到一个成熟的项目中

    Gradle编译JUnit单元测试(加上一些通过示例的测试) AssertJ , Mockito用于平稳的单元测试JaCoCo用于测试覆盖率的度量(有关生成的Java代码的报告,而不是有关Kotlin代码的报告) 从Maven Central的jCenter获取...

    SpringBoot实战:整合jUnit测试框架

    4. **测试覆盖率**:尽可能提高测试覆盖率,确保大部分代码都经过测试。 5. **持续集成**:将单元测试集成到持续集成(CI)流程中,每次代码提交都自动执行测试。 通过以上步骤,你就能在SpringBoot项目中成功整合并...

Global site tag (gtag.js) - Google Analytics