2013-09-25 223 views
6

是否有人能夠從Maven構建中獲得在JaCoCo中工作的JMockit和Powermock單元測試的單元測試覆蓋率?Powermock和JMockit單元測試的測試覆蓋率

我有一個Powermock單元測試的現有測試集,我想逐步遷移到JMockit。但我需要能夠在一份報告中看到所有單元測試的測試覆蓋率,最好是在Sonar中。

我確實通過將JaCoCo置於「脫機」模式中,將JMockit和Powermock測試與Surefire/JaCoCo一起運行(否則,我有一個問題,其中一個代理未在測試結束時被終止,然後mvn clean無法刪除生成的target \ surefire \ surefirebooter2967126910681005991.jar下次運行)。但是沒有爲JMockit測試生成覆蓋率。

如果你有這個工作,請張貼你的朋友的一些摘錄。

這是我的聚甲醛是什麼樣子(注意萬無一失插件congigured與reuseForks =假要解決在Powermock PermGen的內存泄漏,這是主要的原因遷移到JMockit之一)

 <profile> 
     <!-- use this profile to perform Sonar analysis --> 
     <id>sonar</id> 
     <properties> 
      <sonar.language>java</sonar.language> 
      <!-- Tells Sonar to use the generated test coverage report --> 
      <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis> 
      <!-- Tells Sonar to use JaCoCo as the code coverage tool --> 
      <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin> 
      <sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin> 
     </properties> 
     <build> 
      <plugins> 
       <!-- surefire (junit) plugin config with JaCoCo listener --> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <version>2.16</version> 
        <configuration> 
         <!-- note: use single JVM to append to JaCoCo coverage file --> 
         <forkCount>1</forkCount> 
         <reuseForks>false</reuseForks> 
         <argLine>-XX:MaxPermSize=256m </argLine> 
         <systemPropertyVariables> 
          <jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile> 
         </systemPropertyVariables> 
        </configuration> 
       </plugin> 

       <!-- JaCoCo (Sonar) plugin config--> 
       <plugin> 
        <groupId>org.jacoco</groupId> 
        <artifactId>jacoco-maven-plugin</artifactId> 
        <version>0.6.3.201306030806</version> 
        <executions> 
         <execution> 
          <id>instrument</id> 
          <phase>process-classes</phase> 
          <goals> 
           <goal>instrument</goal> 
          </goals> 
         </execution> 
         <execution> 
          <id>restore</id> 
          <phase>site</phase> 
          <goals> 
           <goal>restore-instrumented-classes</goal> 
           <goal>report</goal> 
          </goals> 
         </execution> 
         <execution> 
          <id>check</id> 
          <goals> 
           <goal>check</goal> 
          </goals> 
          <configuration> 
           <rules> 
            <rule> 
             <element>BUNDLE</element> 
             <limits> 
              <limit> 
               <counter>COMPLEXITY</counter> 
               <value>COVEREDRATIO</value> 
               <minimum>0.0</minimum> 
              </limit> 
             </limits> 
            </rule> 
           </rules> 
          </configuration> 
         </execution> 
        </executions> 
        <configuration> 
         <append>true</append> 
        </configuration> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 

回答

0

在classpath或jacoco agent.jar沒有添加到測試類路徑之後,任何一個插裝類都會被傳遞。

要檢查兩個posibilities檢查其中已儀表類,與-X標誌運行mvn和檢查測試執行類路徑(見路徑元素,並且如果jacoco劑是類路徑上順序。)