<plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.5</version> <executions> <execution> <id>prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> <configuration> <!--指定jacoco.exec的目录--> <destFile>target/jacoco.exec</destFile> <propertyName>jacocoArgLine</propertyName> </configuration> </execution> <execution> <id>check</id> <goals> <goal>check</goal> </goals> </execution> <execution> <id>report</id> <phase>prepare-package</phase> <goals> <goal>report</goal> </goals> </execution> </executions> <!-- Configuration 里面写配置信息 --> <configuration> <!-- rules里面指定覆盖规则 --> <rules> <rule implementation="org.jacoco.maven.RuleConfiguration"> <element>BUNDLE</element> <limits> <!-- 指定方法覆盖到80% --> <limit implementation="org.jacoco.report.check.Limit"> <counter>METHOD</counter> <value>COVEREDRATIO</value> <minimum>0.80</minimum> </limit> <!-- 指定指令覆盖到80% --> <limit implementation="org.jacoco.report.check.Limit"> <counter>INSTRUCTION</counter> <value>COVEREDRATIO</value> <minimum>0.80</minimum> </limit> <!-- 指定行覆盖到80% --> <limit implementation="org.jacoco.report.check.Limit"> <counter>LINE</counter> <value>COVEREDRATIO</value> <minimum>0.80</minimum> </limit> <!-- 指定类覆盖到100%,不能遗失任何类 --> <limit implementation="org.jacoco.report.check.Limit"> <counter>CLASS</counter> <value>MISSEDCOUNT</value> <maximum>0</maximum> </limit> </limits> </rule> </rules> </configuration> </plugin>
<?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>com.soos</groupId> <artifactId>apps</artifactId> <version>1.0-SNAPSHOT</version> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!-- sonar单测扫描 --> <jacoco.version>0.8.5</jacoco.version> <jacoco.reportPath>${project.basedir}/target/jacoco-ut.exec</jacoco.reportPath> </properties> <dependencies> <dependency> <groupId>io.qameta.allure</groupId> <artifactId>allure-junit4</artifactId> <version>2.16.0</version> </dependency> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-library</artifactId> <version>2.2</version> <!-- <scope>test</scope>--> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.1</version> <!-- <scope>test</scope>--> </dependency> <dependency> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.5</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> </plugin> <!-- <plugin>--> <!-- <groupId>org.apache.maven.plugins</groupId>--> <!-- <artifactId>maven-surefire-plugin</artifactId>--> <!-- <version>2.7.1</version>--> <!-- <configuration>--> <!-- <skipTests>false</skipTests>--> <!-- <!–表示执行任何子目录下所有命名以Test结尾的java类 –>--> <!-- <includes>--> <!-- <include>**/*Test.java</include>--> <!-- </includes>--> <!-- <!–表示不执行任何子目录下所有命名以Test开头的java类 –>--> <!--<!– <excludes>–>--> <!--<!– <exclude>**/Test*.java</exclude>–>--> <!--<!– </excludes>–>--> <!-- <testFailureIgnore>true</testFailureIgnore>--> <!-- <argLine>--> <!-- -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.5/aspectjweaver-1.9.5.jar"--> <!-- </argLine>--> <!-- <properties>--> <!-- <property>--> <!-- <name>listener</name>--> <!-- <value>io.qameta.allure.junit4.AllureJunit4</value>--> <!-- </property>--> <!-- </properties>--> <!-- </configuration>--> <!-- <dependencies>--> <!-- <dependency>--> <!-- <groupId>org.aspectj</groupId>--> <!-- <artifactId>aspectjweaver</artifactId>--> <!-- <version>1.9.5</version>--> <!-- </dependency>--> <!-- </dependencies>--> <!-- </plugin>--> <!-- <plugin>--> <!-- <groupId>org.jacoco</groupId>--> <!-- <artifactId>jacoco-maven-plugin</artifactId>--> <!-- <version>0.8.5</version>--> <!-- <executions>--> <!-- <execution>--> <!-- <id>prepare-agent</id>--> <!-- <goals>--> <!-- <goal>prepare-agent</goal>--> <!-- </goals>--> <!-- <configuration>--> <!-- <!–指定jacoco.exec的目录–>--> <!-- <destFile>target/jacoco.exec</destFile>--> <!-- <propertyName>jacocoArgLine</propertyName>--> <!-- </configuration>--> <!-- </execution>--> <!-- <execution>--> <!-- <id>check</id>--> <!-- <goals>--> <!-- <goal>check</goal>--> <!-- </goals>--> <!-- </execution>--> <!-- <execution>--> <!-- <id>report</id>--> <!-- <phase>prepare-package</phase>--> <!-- <goals>--> <!-- <goal>report</goal>--> <!-- </goals>--> <!-- </execution>--> <!-- </executions>--> <!-- <!– Configuration 里面写配置信息 –>--> <!-- <configuration>--> <!-- <rules>--> <!-- <rule implementation="org.jacoco.maven.RuleConfiguration">--> <!-- <element>BUNDLE</element>--> <!-- <limits>--> <!-- <!– 指定方法覆盖到80% –>--> <!-- <limit implementation="org.jacoco.report.check.Limit">--> <!-- <counter>METHOD</counter>--> <!-- <value>COVEREDRATIO</value>--> <!-- <minimum>0.80</minimum>--> <!-- </limit>--> <!-- <!– 指定指令覆盖到80% –>--> <!-- <limit implementation="org.jacoco.report.check.Limit">--> <!-- <counter>INSTRUCTION</counter>--> <!-- <value>COVEREDRATIO</value>--> <!-- <minimum>0.80</minimum>--> <!-- </limit>--> <!-- <!– 指定行覆盖到80% –>--> <!-- <limit implementation="org.jacoco.report.check.Limit">--> <!-- <counter>LINE</counter>--> <!-- <value>COVEREDRATIO</value>--> <!-- <minimum>0.80</minimum>--> <!-- </limit>--> <!-- <!– 指定类覆盖到100%,不能遗失任何类 –>--> <!-- <limit implementation="org.jacoco.report.check.Limit">--> <!-- <counter>CLASS</counter>--> <!-- <value>MISSEDCOUNT</value>--> <!-- <maximum>0</maximum>--> <!-- </limit>--> <!-- </limits>--> <!-- </rule>--> <!-- </rules>--> <!-- </configuration>--> <!-- </plugin>--> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.version}</version> <configuration> <!-- <includes> <!–覆盖率计算包含的类–>--> <!-- <include>com/*</include>--> <!-- </includes>--> <!-- <excludes> <!–排除像Pojo、配置等无单元测试意义的类。如有,在Sonar服务端也需要配合排除(Ignore Code Coverage: https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/#header-5)–>--> <!-- <exclude>**/po/**/*</exclude>--> <!-- <exclude>**/config/**/*</exclude>--> <!-- </excludes>--> </configuration> <executions> <execution> <id>default-prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> <configuration> <propertyName>surefireArgLine</propertyName> </configuration> </execution> <execution> <id>report</id> <phase>prepare-package</phase> <goals> <goal>report</goal><!--生成覆盖率文件和报告--> </goals> <configuration> <dataFile>${jacoco.reportPath}</dataFile> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> <configuration> <useSystemClassLoader>false</useSystemClassLoader> <forkMode>once</forkMode> <reuseForks>true</reuseForks> <testFailureIgnore>true</testFailureIgnore> <!--suppress UnresolvedMavenProperty --> <argLine>-Dfile.encoding=UTF-8 ${surefireArgLine}</argLine> <systemPropertyVariables> <jacoco-agent.destfile>${jacoco.reportPath}</jacoco-agent.destfile> </systemPropertyVariables> </configuration> </plugin> </plugins> </build> </project>
命令:mvn test jacoco:report
分类:
测试
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)