jacoco接口测试覆盖率maven插件jacoco-maven-plugin

IDEA有自己的coverage但是检测的不够全面,jacoco强调按照自己的规则来控制测试覆盖率

本文采取的是maven的jacoco插件,目的为了防止覆盖率过低,当不能通过jacoco检测(自己可以设置项目覆盖率)就不能打包

 

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>${jacoco-maven-plugin.version}</version>
    <executions>
//在unit测试之前
        <execution>
            <id>pre-unit-tests</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
            <configuration>
                <!-- Sets the path to the file which contains the execution data. -->
                <destFile>${project.testresult.directory}/coverage/jacoco/jacoco.exec</destFile>
            </configuration>
        </execution>
       //执行检查
        <execution>
            <id>check</id>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
        <!-- Ensures that the code coverage report for unit tests is created after unit tests have been run -->
       //导出报告      
      <execution>
            <id>post-unit-test</id>
            <phase>test</phase>
            <goals>
                <goal>report</goal>
            </goals>
            <configuration>
                <dataFile>${project.testresult.directory}/coverage/jacoco/jacoco.exec</dataFile>
                //生成的测试报告位置
                <outputDirectory>${project.testresult.directory}/coverage/jacoco</outputDirectory>
            </configuration>
        </execution>
    </executions>
    <configuration>
        <destFile>${project.testresult.directory}/coverage/jacoco/jacoco.exec</destFile>
        <dataFile>${project.testresult.directory}/coverage/jacoco/jacoco.exec</dataFile>
        <rules>
            <rule>
                <element>BUNDLE</element>
              //排除不需要啊检测的包,但是但是一直没生效,我现在都不知道原因,我照着官网搞的啊。放在limit里面也没用
                <excludes>
                    <exclude>com.jnc.api.domain.entity</exclude>
                    <exclude>com.jnc.api.domain.repository</exclude>
                </excludes>
                <limits>
                    <limit>
                        <counter>COMPLEXITY</counter>
                        <value>COVEREDRATIO</value>
                       //最低覆盖率
                        <minimum>0.2</minimum>
                    </limit>
                </limits>
            </rule>
        </rules>
    </configuration>
</plugin>

其实照着官网的走就可以了。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值