2016-03-24 88 views
4

在eclipse中我已經使用EcLEmma來查看單元測試代碼覆蓋率。哪些工作正常。 因此,我試圖用Maven的jacoco插件從maven構建中看到同樣的報告,甚至更好地使用某個配置文件或網站週期。均以慘敗告終maven單元測試代碼覆蓋率

所有建議的解決方案在這裏並沒有爲我

是什麼讓一個UNIST測試代碼覆蓋率報告(與神火)的最佳方式工作? [編輯] 更spefici爲什麼jacoco失敗,我....我得到alswas的 跳繩JaCoCo執行由於缺少執行數據

從POM 在屬性

<jacoco.it.execution.data.file>${project.build.directory}/coverage-reports/jacoco-it.exec</jacoco.it.execution.data.file> 
    <jacoco.ut.execution.data.file>${project.build.directory}/coverage-reports/jacoco-ut.exec</jacoco.ut.execution.data.file> 

在Build部分

 <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.eclipse.m2e</groupId> 
       <artifactId>lifecycle-mapping</artifactId> 
       <version>1.0.0</version> 
       <configuration> 
        <lifecycleMappingMetadata> 
         <pluginExecutions> 
          <pluginExecution> 
           <pluginExecutionFilter> 
            <groupId>org.jacoco</groupId> 
            <artifactId>jacoco-maven-plugin</artifactId> 
            <versionRange>${jacoco.version}</versionRange> 
            <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>${jacoco.ut.execution.data.file}</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>${jacoco.ut.execution.data.file}</dataFile> 
               <!-- Sets the output directory for the code coverage report. --> 
               <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory> 
              </configuration> 
             </execution> 
             <!-- Prepares the property pointing to the JaCoCo runtime agent 
              which is passed as VM argument when Maven the Failsafe plugin is executed. --> 
             <execution> 
              <id>pre-integration-test</id> 
              <phase>pre-integration-test</phase> 
              <goals> 
               <goal>prepare-agent</goal> 
              </goals> 
              <configuration> 
               <!-- Sets the path to the file which contains the execution 
                data. --> 
               <destFile>${jacoco.it.execution.data.file}</destFile> 
               <!-- Sets the name of the property containing the settings for 
                JaCoCo runtime agent. --> 
               <propertyName>failsafeArgLine</propertyName> 
              </configuration> 
             </execution> 
             <!-- Ensures that the code coverage report for integration tests 
              after integration tests have been run. --> 
             <execution> 
              <id>post-integration-test</id> 
              <phase>post-integration-test</phase> 
              <goals> 
               <goal>report</goal> 
              </goals> 
              <configuration> 
               <!-- Sets the path to the file which contains the execution 
                data. --> 
               <dataFile>${jacoco.it.execution.data.file}</dataFile> 
               <!-- Sets the output directory for the code coverage report. --> 
               <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory> 
              </configuration> 
             </execution> 
            </executions> 
           </pluginExecutionFilter> 
          </pluginExecution> 
         </pluginExecutions> 
        </lifecycleMappingMetadata> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 

是我最後一次嘗試,但POM變得沒有任何結果越做越大

failes配置報告插件org.apache.maven.plugins:行家-JXR-插件:2.3

配置報告插件org.jacoco:jacoco-行家-插件:0.7.5.201505241946

跳繩JaCoCo執行由於缺少執行數據文件:...... \目標\ jacoco.exec

跳繩JaCoCo執行由於缺少執行數據文件:...... \目標\ jacoco,它.exec

....=>長項目路徑

+1

使用類似jacoco插件或插件的Cobertura HTML報告。那是什麼?你說你已經試過了,它「失敗了」?嗯。好吧,如果我知道什麼「失敗慘敗」*看起來像*我可能會有所幫助,但是事實上,我猜你已經不幸運了。 – dcsohl

+0

你使用'jacoco-maven-plugin'?請解釋你做了什麼,然後嘗試了一下,然後我們可能會馬上幫忙。 – RobAu

+0

將jacoco的pom碎片添加到問題 – user3732793

回答

6

一如既往溶液讀取其提供例如POMS jacoco documentation

此配置文件的文檔後容易

<profile> 
     <id>test</id> 
     <properties> 
      <env>test</env> 
      <gebEnv>test</gebEnv> 
      <jacoco.skip>false</jacoco.skip> 
      <maven.test.skip>false</maven.test.skip> 
      <skip.unit.tests>false</skip.unit.tests> 
     </properties> 
    </profile> 

這在構建部

 <plugin> 
      <groupId>org.jacoco</groupId> 
      <artifactId>jacoco-maven-plugin</artifactId> 
      <version>${jacoco.version}</version> 
      <executions> 
       <execution> 
        <goals> 
         <goal>prepare-agent</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>report</id> 
        <phase>prepare-package</phase> 
        <goals> 
         <goal>report</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

和這在報告部分

 <plugin> 
      <groupId>org.jacoco</groupId> 
      <artifactId>jacoco-maven-plugin</artifactId> 
      <version>${jacoco.version}</version> 
     </plugin> 

比這做的所有

MVN清潔安裝現場-P測試

感謝

3

感謝user3732793

Personnaly,我只需要加入到我的pom.xml

<project> 
... 

    <dependencies> 
     ... 
    </dependencies> 

    <build> 
     <plugins> 
      ... 
      <!-- Code Coverage report generation --> 
      <plugin> 
       <groupId>org.jacoco</groupId> 
       <artifactId>jacoco-maven-plugin</artifactId> 
       <version>0.7.9</version> 
       <executions> 
        <execution> 
         <goals> 
          <goal>prepare-agent</goal> 
         </goals> 
        </execution> 
        <execution> 
         <id>generate-code-coverage-report</id> 
         <phase>test</phase> 
         <goals> 
          <goal>report</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

然後我正在運行

mvn test 

,我得到下./target/site/jacoco/*.html

+0

上運行它很長一段時間,因爲問題發生了,謝謝分享反正 – user3732793