Unit Test 7--单元测试覆盖率表单生成交付,Jacoco的使用

大家好,我是神韵,是一个技术&生活博主。出文章目的主要是两个,一是好记忆不如烂笔头,记录总结中提高自己。二是希望我的文章可以帮到大家。欢迎来点赞打卡,你们的行动将是我无限的动力。
本篇主题是:单元测试覆盖率表单生成交付,Jacoco的使用

其它文章链接:
Unit Test 1–什么是单元测试
Unit Test 2–IDEA配置并查看单元覆盖率
Unit Test 3–编写单元测试之前需要了解的单元测试框架Mock
Unit Test 4–自动生成单元测试插件之TestMe与Diffblue
Unit Test 5–编写第一个单元测试
Unit Test 6–单元测试踩过的坑
Unit Test 8–单元测试覆盖率、Sonar和Jenkins-待须…

生成覆盖率表单只需要如下几步

1、加入maven运行插件

  <build>
    <finalName>unit test</finalName>
    <plugins>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.5</version>
        <configuration>
          <excludes>
            <!-- 不参与unit test -->
            <exclude>**/*App*</exclude>
            <exclude>**/jackson/**</exclude>
            <exclude>**/remote/**</exclude>
            <exclude>**/entity/**</exclude>
          </excludes>
        </configuration>

        <!-- 配置路径,生成jacoco.exec,生成report等-->
        <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>

针对不需要进行unit test的类及包用exclude进行一遍过滤

2、执行命令 mvn clean install
在这里插入图片描述
或者
在这里插入图片描述
3、install 成功后
在这里插入图片描述
4、查看target目录
生成jacoco-ut上面我们配置的文件名称
在这里插入图片描述
5、查看覆盖率
在这里插入图片描述
打开index.html
在这里插入图片描述

本文结束!

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值