念念不忘,必有回响
引言
- 我们要做java代码覆盖率检查
- 我们要对增量代码的覆盖率检查
- 我们要merge代码的时候自动检查覆盖率
出于以上目的,我们开始讲如何做,很多代码是站在前人的肩上进行的
思路参考:https://www.cnblogs.com/cocc/p/12365950.html
大致思路
- 本地查看代码覆盖率
- 提交gitlab上
- merge_requests时触发pipeline进行检查,不通过禁止merge(gitlb版本要求14.9以上,低于这个版本的也有解决方案,也会提到,gitlab域名/help可以查看版本)
环境准备
pom文件
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${project.parent.version}</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
执行mvn install,会在target/site/下看到jacoco的目标,用网页打开就就可以看到单元测试的代码覆盖率
图一
图二
增量代码检查
上边得到的全量,现在如何将全量代码的变成增量的?
python代码参考的https://www.cnblogs.com/