3

mvn サイト構築の一環として、Cobertura テスト カバレッジ レポートを実行しようとしているマルチプロジェクトがあります。子プロジェクトで Cobertura を実行することはできますが、ユニット テストでヒットしたコード行がレポートで強調表示されているにもかかわらず、誤って 0% のカバレッジがレポートされます。

mvn 2.0.8 を使用しています。mvn clean sitemvn clean site:stageおよび を実行してみmvn clean package siteました。テストが実行されていることはわかっています。それらは確実なレポート (txt/xml とサイト レポートの両方) に表示されます。構成に何か不足していますか? Cobertura はマルチプロジェクトで正しく動作しませんか?

これは親 .pom にあります:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <inherited>true</inherited>
                <executions>
                    <execution>
                        <id>clean</id>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
<reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <inherited>true</inherited>
        </plugin>
    </plugins>
</reporting>

子.pomsで次のものを使用して、または使用せずに実行してみました:

    <reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
        </plugin>
    </plugins>
</reporting>

ビルドの出力でこれを取得します。

...
[INFO] [cobertura:instrument]
[INFO] Cobertura 1.9 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Instrumenting 3 files to C:\workspaces\sandbox\CommonJsf\target\generated-classes\cobertura
Cobertura: Saved information on 3 classes.
Instrument time: 186ms

[INFO] Instrumentation was successful.
...
[INFO] Generating "Cobertura Test Coverage" report.
[INFO] Cobertura 1.9 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Cobertura: Loaded information on 3 classes.
Report time: 481ms

[INFO] Cobertura Report generation was successful.

レポートは次のようになります。 コベルチュラレポート

4

4 に答える 4

1

コンパイル フェーズ中に cobertura プラグインの実行が欠落しているため、テストの実行後、サイトのライフサイクルでコードがレポート プラグインによってのみ計測されるようになっていると思われます。したがって、インストルメント化されていないコードで実行されるため、テストの実行は取得されません。ビルド ログをより注意深く分析してください。私が正しければ、確実なテストが cobertura:instrument の前に実行されていることに気付くでしょう。

私の構成はあなたのものと似ていますが、pluginManagement (あなたのように) でクリーンな実行を指定することに加えて、ビルド プラグイン セクションで cobertura プラグインを明示的に指定します。

  <build>
  ...
    <plugins>
    ...
      <plugin>
        <inherited>true</inherited>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>${cobertura.plugin.version}</version>
      </plugin>
    </plugins>
  </build>

私の構成はある程度機能し、すべての Cobertura のものは、すべてのプロジェクトが親として使用するグローバルな組織全体の pom にあります。

このようにして、プロジェクトは pom.xml で Cobertura 関連を何も指定しませんが、それでもカバレッジ レポートを生成します。

于 2009-11-23T14:46:57.057 に答える
1

私が実装したソリューションはやや手動ですが、機能します。これは、Cobertura によって生成された複数の .ser ファイルを結合する 1 つのステップのいくつかのステップで構成されています。これは、maven タスク内で cobertura-merge コマンドライン ツールを使用して実行できます。

あなたが示す出力によると、ファイルは実際には計測されていません.3つのファイルのみが計測されていることがわかります.

于 2010-01-12T19:18:07.900 に答える
1

Cobertura に複数のプロジェクトからのレポートを結合させることに成功していません。これは、複数プロジェクトのレポートで一般的に問題となっています。

私たちは、メトリクス レポートのソリューションとしてソナーを評価しています。マルチプロジェクトを含む、プロジェクト全体の要約メトリックを提供するという素晴らしい仕事をしているようです.

于 2008-09-19T09:38:27.720 に答える
1

@Marcoは正しいです。maven coberturaプラグインにマージゴールがないため、mavenのみを介してこれを正常に達成することはできません。

Maven と ant の目標を組み合わせることで達成できます: http://thomassundberg.wordpress.com/2012/02/18/test-coverage-in-a-multi-module-maven-project/

ただし、テスト対象のプロジェクトが 1 つだけの場合は、マージする必要はありません。テスト プロジェクトでは、テスト対象のプロジェクトから .ser ファイルとインストルメント化されたクラスをコピーできます。

//in test project
<plugin> 
<groupId>com.github.goldin</groupId>
<artifactId>copy-maven-plugin</artifactId>
<version>0.2.5</version>
<executions>
    <execution>
    <id>copy-cobertura-data-from-project-under-test</id>
    <phase>compile</phase>
    <goals>
        <goal>copy</goal>
    </goals>
    <configuration>
    <resources>
        <resource>
                        <directory>${project.basedir}/../<project-under-test>/target/cobertura</directory>
                            <targetPath>${project.basedir}/target/cobertura</targetPath>
                <includes>                  
                              <include>*.ser</include>
                </includes>
           </resource>
           <resource>
                    <directory>${project.basedir}/../<project-under-test>/target/generated-classes/cobertura/</directory>
                    <targetPath>${project.basedir}/target/generated-classes/cobertura</targetPath>
                    <preservePath>true</preservePath>
           </resource>
        </resources>
            </configuration>
        </execution>
</executions>
</plugin>

//in parent project
<build>
<plugins>
    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <configuration>
        <format>xml</format>
        <aggregate>true</aggregate>
    </configuration>
    <executions>
        <execution>
                    <goals>
                <goal>clean</goal>
            </goals>
        </execution>
    </executions>
</plugin>
    </plugins>
</build>
<reporting>
<plugins>
    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <version>${cobertura.version}</version>
        </plugin>
</plugins>
 </reporting>
于 2013-05-11T06:56:24.357 に答える