使用MAVEN+Jacoco统计单元测试的代码覆盖率

时间:2025-04-12 07:14:47
< plugin >
     < groupId ></ groupId >
     < artifactId >maven-surefire-plugin</ artifactId >
     < configuration >
         < skip >false</ skip >
         < testFailureIgnore >true</ testFailureIgnore >
         < argLine >${surefireArgLine}</ argLine >
     </ configuration >
</ plugin >
< plugin >
     < groupId ></ groupId >
     < artifactId >jacoco-maven-plugin</ artifactId >
     < version >0.7.8</ version >
     < configuration >
         < destFile >${}/coverage-reports/</ destFile >
         < dataFile >${}/coverage-reports/</ dataFile >
         < skip >${skipTests}</ skip >
         < output >file</ output >
         < append >true</ append >
     </ configuration >
     < executions >
         < execution >
             < id >pre-unit-test</ id >
             < goals >
                 < goal >prepare-agent</ goal >
             </ goals >
             < configuration >
                 < propertyName >surefireArgLine</ propertyName >
             </ configuration >
         </ execution >
         < execution >
             < id >post-unit-test</ id >
             < phase >test</ phase >
             < goals >
                 < goal >report</ goal >
             </ goals >
             < configuration >
                 < outputDirectory >${}/jacoco-ut</ outputDirectory >
             </ configuration >
         </ execution >
     </ executions >
</ plugin >