解決sonar單元測試覆蓋率為0的問題


pom.xml中添加jacoco插件

<plugin>
   <groupId>org.jacoco</groupId>
   <artifactId>jacoco-maven-plugin</artifactId>
   <version>0.7.9</version>
   <configuration>
      <classDumpDir>target/classes</classDumpDir>
      <includes>
         <include>com///**</include>
      </includes>
   </configuration>
   <executions>
      <execution>
         <id>default-prepare-agent</id>
         <goals>
            <goal>prepare-agent</goal>
         </goals>
      </execution>
      <execution>
         <id>default-prepare-agent-integration</id>
         <goals>
            <goal>prepare-agent-integration</goal>
         </goals>
      </execution>
      <execution>
         <id>default-report</id>
         <goals>
            <goal>report</goal>
         </goals>
      </execution>
      <execution>
         <id>default-report-integration</id>
         <goals>
            <goal>report-integration</goal>
         </goals>
      </execution>
      <execution>
         <id>report-aggregate</id>
         <phase>verify</phase>
         <goals>
            <goal>report-aggregate</goal>
         </goals>
      </execution>
      <execution>
         <id>default-merge</id>
         <goals>
            <goal>merge</goal>
         </goals>
      </execution>
   </executions>
</plugin>

<build>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.8</version>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-agent</goal>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

 

執行單元測試命令:mvn test

結果在target目錄下生產jacoco.exec文件,表明jacoco正確執行


執行sonar命令:mvn sonar:sonar -Dsonar.host.url=http://localhost:9000 -Dsonar.login=[yours id]

 

鏈接:https://my.oschina.net/u/2274056/blog/3211734


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM