随笔都是学习笔记
随笔仅供参考,为避免笔记中可能出现的错误误导他人,请勿转载。
<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>-->
<!--                    &lt;!&ndash;表示执行任何子目录下所有命名以Test结尾的java类 &ndash;&gt;-->
<!--                    <includes>-->
<!--                        <include>**/*Test.java</include>-->
<!--                    </includes>-->
<!--                    &lt;!&ndash;表示不执行任何子目录下所有命名以Test开头的java类 &ndash;&gt;-->
<!--&lt;!&ndash;                    <excludes>&ndash;&gt;-->
<!--&lt;!&ndash;                        <exclude>**/Test*.java</exclude>&ndash;&gt;-->
<!--&lt;!&ndash;                    </excludes>&ndash;&gt;-->
<!--                    <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>-->
<!--                            &lt;!&ndash;指定jacoco.exec的目录&ndash;&gt;-->
<!--                            <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>-->

<!--                &lt;!&ndash; Configuration 里面写配置信息 &ndash;&gt;-->
<!--                <configuration>-->
<!--                    <rules>-->
<!--                        <rule implementation="org.jacoco.maven.RuleConfiguration">-->
<!--                            <element>BUNDLE</element>-->
<!--                            <limits>-->
<!--                                &lt;!&ndash; 指定方法覆盖到80% &ndash;&gt;-->
<!--                                <limit implementation="org.jacoco.report.check.Limit">-->
<!--                                    <counter>METHOD</counter>-->
<!--                                    <value>COVEREDRATIO</value>-->
<!--                                    <minimum>0.80</minimum>-->
<!--                                </limit>-->
<!--                                &lt;!&ndash; 指定指令覆盖到80% &ndash;&gt;-->
<!--                                <limit implementation="org.jacoco.report.check.Limit">-->
<!--                                    <counter>INSTRUCTION</counter>-->
<!--                                    <value>COVEREDRATIO</value>-->
<!--                                    <minimum>0.80</minimum>-->
<!--                                </limit>-->
<!--                                &lt;!&ndash; 指定行覆盖到80% &ndash;&gt;-->
<!--                                <limit implementation="org.jacoco.report.check.Limit">-->
<!--                                    <counter>LINE</counter>-->
<!--                                    <value>COVEREDRATIO</value>-->
<!--                                    <minimum>0.80</minimum>-->
<!--                                </limit>-->
<!--                                &lt;!&ndash; 指定类覆盖到100%,不能遗失任何类 &ndash;&gt;-->
<!--                                <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> &lt;!&ndash;覆盖率计算包含的类&ndash;&gt;-->
<!--                        <include>com/*</include>-->
<!--                    </includes>-->
<!--                    <excludes> &lt;!&ndash;排除像Pojo、配置等无单元测试意义的类。如有,在Sonar服务端也需要配合排除(Ignore Code Coverage: https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/#header-5)&ndash;&gt;-->
<!--                        <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

posted on 2023-09-26 16:24  时间完全不够用啊  阅读(187)  评论(0编辑  收藏  举报