2016-10-30 31 views
1

我有單元測試,我想在代碼覆蓋率結果報告。 當我運行與Maven的測試,我在日誌:JaCoCo Maven插件爲什麼跳過報告?

[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.4.201502262128:report (post-unit-test) @ che-core-api-git --- 
[INFO] Skipping JaCoCo execution due to missing execution data file:C:\dev\eclipse_che_core\platform-api\che-core-api-git\target\coverage-reports\jacoco-ut.exec 

這是我的POM的相關部分。

<plugin> 
    <groupId>org.jacoco</groupId> 
    <artifactId>jacoco-maven-plugin</artifactId> 
    <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> 

爲什麼插件跳過執行?我怎樣才能解決這個問題?

回答

1

代碼覆蓋報告的第一步是啓動JaCoCo代理,通過調用插件的prepare-agent目標來完成。這個目標的目的是:

準備一個指向JaCoCo運行時代理的屬性,該屬性可以作爲VM參數傳遞給被測試的應用程序。根據默認具有下列名稱的屬性的項目包裝類型設置:

  • tycho.testArgLine包裝類型eclipse-test-plugin
  • argLine否則。

您當前的配置中正確設置一個destFile,稍後使用的report目標及其dataFile參數。

問題是指向JaCoCo代理的屬性未正確使用。您的JaCoCo Maven插件的配置將propertyName參數surefireArgLine

<propertyName>surefireArgLine</propertyName> 

這意味着JaCoCo會的路徑,其運行時的代理存儲在這個屬性,並且當Surefire Plugin被調用的測試,此屬性將需要添加到VM參數中。但是,Surefire插件在測試期間不使用surefireArgLine來添加VM參數;更具體地說,正確的參數被稱爲argLine

在命令行上設置的任意JVM選項。

因此,JaCoCo設置指向其代理的屬性surefireArgLine在測試期間未使用。爲了解決這個問題,可以配置一定能成功的插件來考慮這個新屬性:

<plugin> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.19.1</version> 
    <configuration> 
    <argLine>${surefireArgLine}</argLine> 
    </configuration> 
</plugin> 

這將告訴神火插件啓動測試時使用的新屬性surefireArgLine爲VM參數。隨着這一變化,您將在日誌中看到:

[INFO] --- jacoco-maven-plugin:0.7.6.201602180812:report (post-unit-test) @ test --- 
[INFO] Analyzed bundle 'test' with 3 classes 

請注意,默認情況下,需要這一切都不:正如前文所說,JaCoCo存儲由默認情況下此VM參數在argLine財產,這正是用於注入自定義VM參數的Surefire插件參數的名稱。因此,另一種解決方案是隻刪除您

<propertyName>surefireArgLine</propertyName> 

配置元素,並讓默認一命嗚呼。

+0

我做了改變,現在我ahve covergae的報告,但爲空,也該文件夾網站jave index.html,但當我打開它,我沒有看到任何結果。 – user1365697

+0

我更新了問題 – user1365697

+0

中的pom.xml我現在沒有得到信息,但也沒有得到任何結果 – user1365697