【初次尝试】在Idea Maven项目中引入jacoco-maven-plugin生成测试代码覆盖率报告

pom.xml文件,其中<groupId>org.yjm</groupId>要更改

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.yjm</groupId>
    <artifactId>JUnit</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <properties>
        <maven.compiler.source>16</maven.compiler.source>
        <maven.compiler.target>16</maven.compiler.target>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.9</version>
                <configuration>
                    <!--定义输出的文件夹-->
                    <outputDirectory>target/jacoco-report</outputDirectory>
                    <!--执行数据的文件-->
                    <dataFile>${project.build.directory}/jacoco.exec</dataFile>
                    <!--要从报告中排除的类文件列表,支持通配符(*和?)。如果未指定则不会排除任何内容-->
                    <!-- <excludes>**/test/*.class</excludes> -->
                    <!--包含生成报告的文件列表,支持通配符(*和?)。如果未指定则包含所有内容-->
                    <includes></includes>
                    <!--HTML 报告页面中使用的页脚文本。-->
                    <footer></footer>
                    <!--生成报告的文件类型,HTML(默认)、XML、CSV-->
                    <formats>HTML</formats>
                    <!--生成报告的编码格式,默认UTF-8-->
                    <outputEncoding>UTF-8</outputEncoding>
                    <!--抑制执行的标签-->
                    <skip></skip>
                    <!--源文件编码-->
                    <sourceEncoding>UTF-8</sourceEncoding>
                    <!--HTML报告的标题-->
                    <title>${project.name}</title>
                </configuration>
                <executions>
                    <execution>
                        <id>jacoco-check</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <rule>
                                    <element>PACKAGE</element>
                                    <limits>
                                        <limit>
                                            <counter>LINE</counter>
                                            <value>COVEREDRATIO</value>
                                            <!-- 配置最低覆盖率为0.1(10%) -->
                                            <minimum>0.1</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                            </rules>
                        </configuration>
                    </execution>
                    <execution>
                        <id>generate-code-coverage-report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

引入后打开控制台,以项目所在目录为路径,运行
mvn clean test org.jacoco:jacoco-maven-plugin:0.8.9:prepare-agent install

在这里插入图片描述

即可在target中找到生成的报告,打开index.html即可查看

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

深|码|洞|悉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值