2016-03-24 9 views
2

テスト結果の出力にはsonarqubeを使用し、テストケースのテストにはmavenとjacocoを使用しています。maven jacocoプラグインはカバレッジレポートを生成しません

Sonarqubeのバージョンは5.4 Mavenのバージョンである3.3.9 Jacocoバージョン0.7

ですこれは私もこのlink hereを次のですが、ファイルのために、私は使用しています私のpom.xml

<?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> 

ですここのものはenter link description hereです。 9000 /それは0.00パーセントのコードカバレッジを表示しますが、私はbuiildが成功を返しますが、何のコードカバレッジがない

mvn clean test 
mvn clean verify 
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install 
mvn sonar:sonar 

をテストするためのプロジェクトは、私はまた、ローカルホストをsonarqubeに行くことによってこれを確認し、生成構築方法

この単体テストはすべて「成功している」として成功したものとして提示されます。

この問題の原因は何ですか?私はまだこのすべてに新しいです。

+0

なぜ 'mvn clean test'と' mvn clean verify' ...と 'mvn clean ... install'を実行していますか?単一の 'mvnクリーンインストール 'を実行し、' mvn sonar:sonar'でもかまいません。 – khmarbaise

+0

@khmarbaise最初にテストして確認する必要があることを私は読んでいますか?または私が欲しいものを達成するために必要なステップは何ですか?私はちょうど私が読んだすべてを試みた。 – makingitwork

+0

こんにちは、どのJavaバージョンを使用していますか? –

答えて

2

セットアップは私の視点からは大丈夫です。

レポートファイルのデフォルト名を変更しました。したがって、ソナーアナライザーにもそのことを伝える必要があると思います。

単体テストのjacocoのデフォルトは、${project.build.directory}/jacoco.exec です。これもまた、ソナーの名前がピックアップしようとします。

あなたは、単にソナー・アナライザのための場所を示すために、プロパティを設定することができます。

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

あなたjaccoファイルが存在し、非空であるかどうかを確認してください - いったんので、ソナーは、遅かれ早かれ、それを拾うかどう場所が正しく設定されています。

+0

私はそれを自分のプロパティに追加しようとし、それが動作するかどうかを確認しようと思うでしょう:) – makingitwork

+1

ありがとうございます! – makingitwork

関連する問題