2016-03-24 22 views
2

Test sonuçları için maven ve jacoco kullanırken test sonuçları için çıkış olarak sonarqube kullanıyorum.maven jacoco eklentisi kapsama raporu üretmiyor

Sonarqube versiyonu 5.4 Maven sürüm 3.3.9 Jacoco sürüm 0.7

olan bu

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>org.sonarqube</groupId> 
    <artifactId>example-ut-maven-jacoco</artifactId> 
    <version>1.0-SNAPSHOT</version> 

    <name>Java :: UT Coverage with JaCoCo :: Maven</name> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <!-- Minimal supported version is 4.7 --> 
     <version>4.11</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.jacoco</groupId> 
     <artifactId>jacoco-maven-plugin</artifactId> 
     <version>0.7.6.201602180812</version> 
    </dependency> 

    </dependencies> 

    <build> 
    <plugins> 
     <plugin> 
    <groupId>org.jacoco</groupId> 
    <artifactId>jacoco-maven-plugin</artifactId> 
    <version>0.7.5.201505241946</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.15</version> 
     <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> 
     </configuration> 
    </plugin> 
    </plugins> 
    </build> 



</project> 

Ben de bu link here takip ediyorum ama dosyalar için kullanıyorum benim pom.xml olduğunu Burada olanlar enter link description here. Ben test için projeyi nasıl inşa

Bu

buiild başarılı döndürür ama hiçbir kod kapsamı ben de localhost sonarqube giderek bu kontrol oluşturulan vardır

mvn clean test 
mvn clean verify 
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install 
mvn sonar:sonar 
: 9000/o 0.00% kodu kapsama ancak görüntüler Birim testi hepsi başarılı "başarılı" olarak sunulur.

Bu soruna neden olabilecek herhangi bir fikir var mı? Ayrıca tüm bunlara hala yeniyim.

+0

Neden "mvn clean test" ve "mvn clean verify" ... ve "mvn clean ... install" çalışıyorsunuz? Tek bir “mvn clean install” çalıştırıyor ve “mvn sonar: sonar” yeterli olabilir. – khmarbaise

+0

@khmarbaise İlk önce sınamanız ve doğrulamak gerektiğini okudum mu? ya da ne istediğimi gerçekleştirmek için gereken adımlar nelerdir? Sadece okuduğum herşeyi denedim. – makingitwork

+0

Merhaba, Hangi java sürümünü kullanıyorsunuz? –

cevap

2

Kurulum benim bakış açımdan iyi görünüyor.

Rapor dosyasının varsayılan adını değiştirdiniz. Bu yüzden bunu sonar analizörüne de söylemeniz gerektiğini tahmin ediyorum.

Birim testleri için jacoco varsayılan değeri: ${project.build.directory}/jacoco.exec Ayrıca, sonar adı da almaya çalışacaktır.

Sadece sonar analizörü konumunu belirtmek için bir özelliği ayarlayabilirsiniz:

<properties 
    <sonar.jacoco.reportPath>${project.build.directory}/coverage-reports/jacoco-ut.exec</sonar.jacoco.reportPath> 
    ... 

sizin Jacco dosya var ve olmayan boşsa kontrol edin - böylece bir kez sonar er ya da geç onu almak eğer konum doğru şekilde yapılandırılmıştır.

+0

Ben özellikleri eklemek ve çalışıp çalışmadığını görmek için çalışacağız :) – makingitwork

+1

Teşekkürler! – makingitwork

İlgili konular