2016-03-09 46 views
-1

我手邊以下任務:IT代碼覆蓋有聲納

- 找到它的代碼覆蓋率的一個項目

鑑於情況:

- IT代碼駐留在一個單獨的存儲庫來實際生產代碼

- 測試創建的生產代碼位於多個git存儲庫中。

- 以上所有使用maven並用Java編寫。

我試過以下不同的教程和博客,但無法找到更簡單的答案。

任何人都可以指向我正確的資源或給我一個啓動啓動的提示?

+0

您好,歡迎來到StackOverflow。請花一些時間閱讀幫助頁面,尤其是名爲[「我可以詢問什麼主題?」(http://stackoverflow.com/help/on-topic)和[「我應該問什麼類型的問題避免問?「](http://stackoverflow.com/help/dont-ask)。更重要的是,請閱讀[Stack Overflow問題清單](http://meta.stackexchange.com/q/156810/204922)。您可能還想了解[最小,完整和可驗證的示例](http://stackoverflow.com/help/mcve) –

+0

也許[程序員.stackexchange.com](http://programmers.stackexchange.com)是您的問題的正確位置。 – JimHawkins

+0

@Ulrich這個問題對於程序員來說是不合適的 - 它會很快被拒絕並關閉,請參閱[從哪裏開始?](http://meta.programmers.stackexchange.com/a/6367/31260)推薦閱讀:** [Programmers.SE是怎麼回事?堆棧溢出指南](http://meta.programmers.stackexchange.com/q/7182/31260)** – gnat

回答

0

我會盡力回答。我將以UT爲例(IT在maven生命週期構建中不是同一個地方,而不是保證插件是故障保護插件)

假設我們使用JaCoCo作爲代碼覆蓋代理。 在我父POM,在個人資料部分(它是一個多模塊項目)

   <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <version>2.15</version> 
        <configuration> 
         <argLine>${surefireArgLine}</argLine> 
        </configuration> 
       </plugin> 
       <plugin> 
        <groupId>org.jacoco</groupId> 
        <artifactId>jacoco-maven-plugin</artifactId> 
        <version>0.7.4.201502262128</version> 
        <executions> 
         <execution> 
          <id>pre-unit-test</id> 
          <goals> 
           <goal>prepare-agent</goal> 
          </goals> 
          <configuration> 
           <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile> 
           <propertyName>surefireArgLine</propertyName> 
          </configuration> 
         </execution> 
         <execution> 
          <id>post-unit-test</id> 
          <phase>test</phase> 
          <goals> 
           <goal>report</goal> 
          </goals> 
          <configuration> 
           <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile> 
           <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 

現在,當我們建立我們的Maven項目,我們添加輪廓注入JaCoCo代理

clean install -Psonar-coverage 

然後我們可能會告訴聲納分析我們的項目並使用以下命令使用JaCoCo報告:

mvn org.codehaus.mojo:sonar-maven-plugin:2.4:sonar -Dsonar.dynamicAnalysis=reuseReports -Dsonar.java.coveragePlugin=jacoco -Dsonar.forceAnalysis=true -Dsonar.jacoco.reportMissing.force.zero=true -Dsonar.binaries=target/classes -Dsonar.junit.reportsPath=target/surefire-reports -Dsonar.jacoco.reportPath=target/coverage-reports/jacoco-ut.exec -Dsonar.jdbc.driver=com.mysql.jdbc.Driver -Dsonar.jdbc.url=jdbc:<YOUR SONAR INSTALLATION DB> -Dsonar.host.url=<YOUR SONAR INSTALLATION> 
相關問題