天天看点

Maven工程配置代码覆盖工具Jacoco

介绍

pom中加入

<build>
  <plugins>

    <plugin>
      <groupId>org.jacoco</groupId>
      <artifactId>jacoco-maven-plugin</artifactId>
      <version>0.7.5.201505241946</version>
      <executions>
        <execution>
          <id>prepare-agent</id>
          <goals>
            <goal>prepare-agent</goal>
          </goals>
        </execution>
        <execution>
          <id>report</id>
          <phase>prepare-package</phase>
          <goals>
            <goal>report</goal>
          </goals>
        </execution>
        <execution>
          <id>post-unit-test</id>
          <phase>test</phase>
          <goals>
            <goal>report</goal>
          </goals>
          <configuration>
            <dataFile>target/jacoco.exec</dataFile>
            <outputDirectory>target/jacoco-ut</outputDirectory>
          </configuration>
        </execution>
      </executions>
    </plugin>

  </plugins>
</build>      

执行

mvn clean package      

点击targer/jacoco-ut目录下的index.html即可

Maven工程配置代码覆盖工具Jacoco

依次点进各级目录查看即可

继续阅读