1

次の Maven プロジェクト構造を持つ:

-project1          <-- parent pom with two children.
|--module1         <-- web services
\--module1-itest   <-- integration tests written with TestNG

今日の取り組み:

  • module1でmvn sonar:sonarを実行すると、Sonar のダッシュボードの単体テストからのコード カバレッジが表示されます。
  • mvn jetty:runをmodule1 で実行し、その直後に module1-itests でmvn testを実行してテストします。

これが理想的なシナリオとはかけ離れていることは承知しています...ほとんどテストを行わずにレガシープロジェクトを改善しようとするときの中間ステップのようなものです...


私の質問は、module1 の Sonar のダッシュボードで統合テストを実行してコード カバレッジを取得するための最良の方法は何でしょうか?

最初は、module1-itest のコードを module1 に移動し、Failsafe プラグインと十分に文書化された JaCoCo との統合を使用してそれらを実行する傾向があります。このように、Module1 には JUnit 単体テストと TestNG 統合テストが混在し、各グループはそれぞれ Surefire と Failsafe によって実行され、統合前フェーズで Jetty サーバーを起動します。

ただし、両方のプロジェクトを分離しておく理由があるため、次のことを考えています。

  1. 上記のアプローチは良いものですか?
  2. module1 Sonar のダッシュボードでmodule1-itestによって行われたコード カバレッジを含めて、両方のプロジェクトを分離しておくために使用できる他の推奨される方法はありますか?

ありがとう、

4

1 に答える 1

2

これが私たちがそれを解決した方法です:

まとめ

  • Service プロジェクトと Service-itest プロジェクトは、2 つの独立したモジュールです。
  • サービスには単体テストがあり、そのカバレッジはソナーによって報告されます。
  • Service-itests は Cargo を使用してサービス WAR をロードし、統合テストを実行します。この実行で収集されたコード カバレッジは、1 レベル上に報告されます。このようにして、ITests のカバレッジが収集され、モジュール間でマージされ、親プロジェクトの pom レベルでレポートされます。また、このアプローチは、異なる ITests プロジェクト (たとえば、アプリをロードする Cargo を使用するものと JBehave を使用するもの) を持つことができ、独立して進化できるため、気に入っています。

親ポンで:

    <modules>
            <module>service</module>
            <module></module>
            <module>service-itest</module>
        </modules>
    <!-- Sonar -->
            <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
            <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
            <!-- The destination file for the code coverage report has to be set to 
                the same value in the parent pom and in each module pom. Then JaCoCo will 
                add up information in the same report, so that, it will give the cross-module 
                code coverage. -->
            <sonar.jacoco.itReportPath>${project.basedir}/../target/jacoco-itests.exec</sonar.jacoco.itReportPath>
...
<build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.6.3.201306030806</version>
                </plugin>
            </plugins>
        </pluginManagement>
...
<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>our.project.packages.*</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <id>pre-test</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>post-test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

そして -itest プロジェクトの pom.xml ファイルで:

<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <configuration>
                    <!-- The destination file for the code coverage report has to be set 
                        to the same value in the parent pom and in each module pom. Then JaCoCo will 
                        add up information in the same report, so that, it will give the cross-module 
                        code coverage. -->
                    <destFile>${project.basedir}/../target/jacoco-itests.exec</destFile>
                    <includes>
                        <include>our.packages.*</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <id>post-test</id>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <version>1.2.2</version>
                <configuration>
                    <skip>${cargo.skip}</skip>
                    <container>
                        <containerId>jetty7x</containerId>
                        <artifactInstaller>
                            <groupId>org.eclipse.jetty</groupId>
                            <artifactId>jetty-distribution</artifactId>
                            <version>7.6.12.v20130726</version>
                            <type>zip</type>
                        </artifactInstaller>
                    </container>
                    <configuration>
                        <type>standalone</type>
                        <properties>
                            <cargo.servlet.port>${jetty.port}</cargo.servlet.port>
                            <cargo.jvmargs>${argLine}</cargo.jvmargs>
                        </properties>
                        <deployables>
                            <deployable>
                                <artifactId>pam_filetask_manager_service</artifactId>
                                <groupId>${project.groupId}</groupId>
                                <type>war</type>
                                <pingURL>http://server:22000/ping</pingURL>
                                <properties>
                                </properties>
                            </deployable>
                        </deployables>
                    </configuration>
                </configuration>
                <executions>
                    <execution>
                        <id>start-server</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>install</goal>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-server</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
于 2014-07-18T17:11:16.987 に答える