分享

JaCoCo maven 集成测试官方文档

 hh3755 2016-09-21

Maven Plug-in

The JaCoCo Maven plug-in provides the JaCoCo runtime agent to your tests and allows basic report creation.

If you want to have line number information included in the coverage reports or you want source code highlighting the class files of the test target must be compiled with debug information.

When using the maven-surefire-plugin or maven-failsafe-plugin you must not use a forkCount of 0 or set the forkMode to never as this would prevent the execution of the tests with the javaagent set and no coverage would be recorded.

Example

  • The JaCoCo distribution contains a simple example how code coverage can be added to a Maven project.
  • This POM file for a JAR project runs JUnit tests under code coverage and creates a coverage report (target/site/jacoco/index.html).
  • This POM file for a JAR project runs unit tests and integration tests under code coverage and creates two coverage reports, one for unit tests ( target/site/jacoco/index.html) and one for integration tests ( target/site/jacoco-it/index.html).
  • The complete example is located in the ./doc/examples/build folder of the distribution.

Prerequisites

The JaCoCo Maven plug-in requires

  • Maven 2.1.0 or higher and
  • Java 1.5 or higher (for both, the Maven runtime and the test executor).

Usage

The Maven plug-in can be included in your build with the following declaration. Please check here for the latest release version in the repository.

  1. <plugin>
  2.   <groupId>org.jacoco</groupId>
  3.   <artifactId>jacoco-maven-plugin</artifactId>
  4.   <version>0.7.8-SNAPSHOT</version>
  5. </plugin>

To receive a full list of goals and available parameters you can use maven-help-plugin:

mvn help:describe -Dplugin=org.jacoco:jacoco-maven-plugin -Ddetail

Usage of plugin together with maven-site-plugin without explicit selection of reports might lead to generation of redundant aggregate reports. Specify reportSets explicitly to avoid this:

  1. <project>
  2.   <reporting>
  3.     <plugins>
  4.       <plugin>
  5.         <groupId>org.jacoco</groupId>
  6.         <artifactId>jacoco-maven-plugin</artifactId>
  7.         <reportSets>
  8.           <reportSet>
  9.             <reports>
  10.               <!-- select non-aggregate reports -->
  11.               <report>report</report>
  12.             </reports>
  13.           </reportSet>
  14.         </reportSets>
  15.       </plugin>
  16.     </plugins>
  17.   </reporting>
  18. </project>

Goals

The JaCoCo Maven plug-in defines the following goals:

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约