• Springboot 多模块项目集成Jacoco统计单元测试覆盖率


    最外层POM配置

    <plugin>
                    <groupId>org.apache.maven.pluginsgroupId>
                    <artifactId>maven-surefire-pluginartifactId>
                    <version>2.18.1version>
                    <configuration>
                        <testFailureIgnore>truetestFailureIgnore>
                        <forkMode>onceforkMode>
                        <reuseForks>truereuseForks>
                        <useSystemClassLoader>falseuseSystemClassLoader>
                        <argLine>@{argLine}argLine>
                        <includes>
                            <include>**/*Test.javainclude>
                            <include>**/*Test*.javainclude>
                        includes>
                    configuration>
                plugin>
                <plugin>
                    <groupId>org.jacocogroupId>
                    <artifactId>jacoco-maven-pluginartifactId>
                    <version>0.8.6version>
                    <executions>
                        <execution>
                            <id>my-prepare-agentid>
                            <goals>
                                <goal>prepare-agentgoal>
                            goals>
                            <configuration>
                                <propertyName>surefireArgLinepropertyName>
                            configuration>
                        execution>
                        <execution>
                            <id>my-reportid>
                            <phase>testphase>
                            <goals>
                                <goal>report-aggregategoal>
                            goals>
                        execution>
                    executions>
                plugin>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40

    本地统计代码单元测试覆盖率

    mvn test jacoco:prepare-agent jacoco:report jacoco:report-aggregate 
    
    • 1

    远端SonarQube执行

    jenkis服务器需要配置Jacoco

      mvn test jacoco:prepare-agent jacoco:report jacoco:report-aggregate sonar:sonar -Dsonar.projectKey=xxxxx -Dsonar.projectName=xxx
    
    • 1

    注意事项

    Q1 target目录下未编译test目录下的代码

    常见报错:

    Not compiling test sources

    Skipping JaCoCo execution due to missing execution data file.

    修改插件配置

     <plugin>
                    <groupId>org.apache.maven.pluginsgroupId>
                    <artifactId>maven-compiler-pluginartifactId>
                    <version>${version.compiler.plugin}version>
                    <configuration>
                         
                        <skip>falseskip>
                        
                    configuration>
     plugin>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
  • 相关阅读:
    【Java - L - 0102】- m - 二叉树的层序遍历
    【数据结构】堆排序和top-k问题
    [附源码]JAVA毕业设计高校医务管理系统(系统+LW)
    第4章 文件管理
    MySQL存储过程详解与案例应用
    基于Qlearning强化学习的机器人路线规划仿真
    python with as的用法
    南大通用GBase8s 常用SQL语句(236)
    Python(一)
    数据库系列MySQL:数据类型及用途
  • 原文地址:https://blog.csdn.net/istruth/article/details/132587076