2017-01-16 336 views
0

我已經閱讀了大多數類似問題的答案,但沒有一個適合回答我的問題。Jacoco代碼覆蓋率顯示Jenkins覆蓋率爲0%

我在POM文件的個人資料如下:

  <plugins> 
       <plugin> 
        <groupId>org.jacoco</groupId> 
        <artifactId>jacoco-maven-plugin</artifactId> 
        <version>0.7.7.201606060606</version> 
        <executions> 
         <!-- Prepares the property pointing to the JaCoCo runtime agent which 
          is passed as VM argument when Maven the Surefire plugin is executed. --> 
         <execution> 
          <id>pre-unit-test</id> 
          <goals> 
           <goal>prepare-agent</goal> 
          </goals> 
          <configuration> 
           <!-- Sets the path to the file which contains the execution data. --> 
           <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile> 
           <!-- Sets the name of the property containing the settings for JaCoCo 
            runtime agent. --> 
           <propertyName>surefireArgLine</propertyName> 
          </configuration> 
         </execution> 
         <!-- Ensures that the code coverage report for unit tests is created 
          after unit tests have been run. --> 
         <execution> 
          <id>post-unit-test</id> 
          <phase>test</phase> 
          <goals> 
           <goal>report</goal> 
          </goals> 
          <configuration> 
           <!-- Sets the path to the file which contains the execution data. --> 
           <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile> 
           <!-- Sets the output directory for the code coverage report. --> 
           <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 

       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <version>2.19.1</version> 
        <configuration> 
         <skip>true</skip> 
        </configuration> 
        <executions> 
         <execution> 
          <id>surefire-unit-tests</id> 
          <phase>test</phase> 
          <goals> 
           <goal>test</goal> 
          </goals> 
          <configuration> 
           <!-- Sets the VM argument line used when unit tests are run. --> 
           <argLine>${surefireArgLine}</argLine> 
           <!-- Skips unit tests if the value of skip.unit.tests property is 
            true --> 
           <skipTests>${skip.unit.tests}</skipTests> 
           <!-- Excludes integration tests when unit tests are run. --> 
           <skip>false</skip> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 

       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-failsafe-plugin</artifactId> 
        <version>2.19.1</version> 
        <executions> 
         <!-- Ensures that both integration-test and verify goals of the Failsafe 
          Maven plugin are executed. --> 
         <execution> 
          <id>integration-tests</id> 
          <goals> 
           <goal>integration-test</goal> 
           <goal>verify</goal> 
          </goals> 
          <configuration> 
           <!-- Sets the VM argument line used when integration tests are run. --> 
           <argLine>${failsafeArgLine}</argLine> 
           <!-- Skips integration tests if the value of skip.integration.tests 
            property is true --> 
           <skipTests>${skip.integration.tests}</skipTests> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 

當我跑我的詹金斯的工作與Maven目標clean install -P test-coverage

我看到這在我的詹金斯登錄:

`[JaCoCo plugin] Collecting JaCoCo coverage data... 
[JaCoCo plugin] **/target/coverage-reports/jacoco-ut.exec;**/target/classes;**/src/main/java; locations are configured 
[JaCoCo plugin] Number of found exec files for pattern **/target/coverage-reports/jacoco-ut.exec: 0 
[JaCoCo plugin] Saving matched execfiles: 
[JaCoCo plugin] Saving matched class directories for class-pattern: **/target/classes: 
[JaCoCo plugin] Saving matched source directories for source-pattern: **/src/main/java: 
[JaCoCo plugin] Loading inclusions files.. 
[JaCoCo plugin] inclusions: [] 
[JaCoCo plugin] exclusions: [] 
[JaCoCo plugin] Thresholds: JacocoHealthReportThresholds [minClass=0, maxClass=0, minMethod=0, maxMethod=0, minLine=0, maxLine=0, minBranch=0, maxBranch=0, minInstruction=0, maxInstruction=0, minComplexity=0, maxComplexity=0] 
[JaCoCo plugin] Publishing the results.. 
[JaCoCo plugin] Loading packages.. 
[JaCoCo plugin] Done. 
[JaCoCo plugin] Overall coverage: class: 0, method: 0, line: 0, branch: 0, instruction: 0` 

這是我爲Jacoco配置的Jenkins配置:

enter image description here

+1

通告模式** /目標/覆蓋的報表/ jacoco-ut.exec發現EXEC文件的行數':0'在詹金斯日誌 - 你需要了解爲什麼沒有這樣的文件,它需要查看遠遠高於此行的構建日誌。 – Godin

+0

@戈丁剛剛在那裏取得了成功。實際上,構建目錄與jenkins作業的工作空間不同。 – ASR

+0

還將exec文件位置更改爲'**/jacoco.exec',最好遵循插件建議的內容。 – ASR

回答

0

在我的情況下,它是無法得到EXEC文件。

這是因爲我的build目錄是不同的,那麼詹金斯作業的工作區。當我將構建目錄更改爲WORKSPACE時,發生了奇蹟。

0

在我來說,我是用jacocoant 0.6和jaCoCo插件詹金斯2.2.0。 從jaCoCo插件github上頁:

版本2.0.0或更高要求使用JaCoCo 0.7.5或更新的版本,如果你的項目仍然使用JaCoCo 0.7.4,該插件將不會顯示任何代碼覆蓋的任何數字更多!在這種情況下,請使用版本1.0.19,直到您可以更新代碼庫中的jacoco。 https://github.com/jenkinsci/jacoco-plugin

0

在我的情況下,Jacoco插件是1.0.19,但我使用Jacoco - Maven的插件0.7.9,它是不兼容的。

所以,改變Jacoco - Maven的插件後0.7.4.x.我得到正確的覆蓋上詹金斯