2012-09-14 185 views
4
使用Jacoco 0%

我使用:IT測試覆蓋率是SONAR

SONAR v.3.2(它有jacoco)

的Maven 3.0.4

遵循 「http://johndobie.blogspot.in/2012/05/easy-unit-and-integration-code-coverage.html#comment-form」 獲得單獨的代碼IT測試覆蓋率爲&。但IT測試覆蓋率顯示爲0%。 它正在生成單獨的jacoco-unit.exec(44kb)& jacoco-it.exec(14kb),但覆蓋範圍僅顯示在SONAR上的單元測試。

日誌顯示爲:

[INFO] [13:10:23.515] Sensor SquidSensor done: 9437 ms 
[INFO] [13:10:23.515] Sensor JaCoCoSensor... 
[INFO] [13:10:23.578] Analysing ...\target\coverage-reports\jacoco-unit.exec 
[INFO] [13:10:30.390] Sensor JaCoCoSensor done: 6875 ms 
[INFO] [13:10:30.390] Sensor JaCoCoItSensor... 
[INFO] [13:10:30.390] Analysing ...\target\coverage-reports\jacoco-it.exec 
[INFO] [13:10:30.469] Sensor JaCoCoItSensor done: 79 ms 
[INFO] [13:10:30.484] Sensor SurefireSensor... 
[INFO] [13:10:30.484] parsing ...\target\surefire-reports 
[INFO] [13:10:30.828] Sensor SurefireSensor done: 344 ms 
[INFO] [13:10:30.828] Sensor CpdSensor... 
[INFO] [13:10:30.828] SonarEngine is used 
[INFO] [13:10:30.844] Cross-project analysis disabled 
[INFO] [13:10:32.312] Sensor CpdSensor done: 1484 ms 
[INFO] [13:10:32.312] Sensor CheckstyleSensor... 

POM文件:

<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/maven-v4_0_0.xsd"> 

    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.csr.lts</groupId> 
    <artifactId>lts-webapp</artifactId> 
    <packaging>war</packaging> 
    <name>LTS Webapp</name> 
    <url>http://maven.apache.org</url> 
    <parent> 
     <groupId>com.csr</groupId> 
     <artifactId>lts</artifactId> 
     <version>0.1-SNAPSHOT</version> 
    </parent> 

    <properties> 
     <coverage.reports.dir>${basedir}/target/coverage-reports</coverage.reports.dir> 
     <sonar.jacoco.reportPath>${coverage.reports.dir}/jacoco-unit.exec</sonar.jacoco.reportPath> 
     <sonar.jacoco.itReportPath>${coverage.reports.dir}/jacoco-it.exec</sonar.jacoco.itReportPath> 
     <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis> 
     <sonar.jacoco.jar>${basedir}/lib/org.jacoco.agent-0.5.10.201208310627-runtime.jar</sonar.jacoco.jar> 
    </properties> 

    <build> 
     <finalName>lts</finalName> 

     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.12.3</version> 
       <dependencies> 
        <dependency> 
         <groupId>org.apache.maven.surefire</groupId> 
         <artifactId>surefire-junit47</artifactId> 
         <version>2.12</version> 
        </dependency> 
       </dependencies> 
       <configuration> 

        <argLine> 
         -javaagent:${sonar.jacoco.jar}=destfile=${sonar.jacoco.reportPath},append=false,includes=com.* 
        </argLine> 
        <includes> 
         <include>**/*Test.java</include> 
         <include>**/Test*.java</include> 
        </includes> 
        <excludes> 
         <exclude>**/IT*.java</exclude> 
        </excludes> 
       </configuration> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-failsafe-plugin</artifactId> 
       <version>2.12.3</version> 
       <dependencies> 
        <dependency> 
         <groupId>org.apache.maven.surefire</groupId> 
         <artifactId>surefire-junit47</artifactId> 
         <version>2.12</version> 
        </dependency> 
       </dependencies> 

       <executions> 
        <execution> 
         <goals> 
          <goal>integration-test</goal> 
         </goals> 
         <configuration> 
          <argLine> 
           -javaagent:${sonar.jacoco.jar}=destfile=${sonar.jacoco.itReportPath},append=false,includes=com.* 
          </argLine> 
          <includes> 
           <include>**/IT*.java</include> 
          </includes> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</project> 
+0

沒有完全分析您的配置,但想到的第一個問題是:您是否在Sonar中添加了Integration Code Coverage小部件?它默認不在默認的儀表板上。 – aquacode

回答

1

您可以查看我們的樣本項目位置:https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/java/code-coverage/combined%20ut-it

你會發現同時具有單元和集成的工程實例由於JaCoCo的報道,測試覆蓋率得到報告

+3

示例項目不再可用(404) –

+0

儘管我們遵循聲納示例和文檔,但我遇到了完全相同的問題。 http://stackoverflow.com/questions/28589790/integration-test-coverage-in-sonarqube-from-jacoco-maven-plug-in-showing-0 –