大規模な Maven プロジェクトに統合テストを追加しようとしています。イベントの望ましい順序は次のとおりです。
- 既存のアーティファクトを消去します。
- 依存関係を解決し、プロジェクトをビルドします。
- Surefire プラグインを介して単体テストを実行します。
- Clover プラグインのフォーク ライフサイクル。
- --- Clover プラグインを使用してソースを計測します。
- --- Clover の project.build.directory と project.build.finalName を変更します。
- --- 新しいディレクトリに Clover インストルメント化プロジェクトをビルドします。
- --- Surefire プラグインを介して Clover の計測ユニット テストを実行します。
- --- Clover のインストルメント化された単体テストからコード カバレッジを確認します。
- --- project.build.directory と project.build.finalName を元の値にリセットします。
- --- フォークされたライフサイクルを終了します (Clover は「テスト」段階でのみフォークします)。
- プロジェクトを WAR ファイルとしてパッケージ化します。
- Tomcat7 プラグインを介してプロジェクト WAR ファイルをローカルでホストします。
- Surefire プラグインを介して Tomcat7 インスタンスに対して統合テストを実行します。
手順 9 を除いて、これはすべて期待どおりに機能します (したがって、質問です)。代わりに、ビルド ディレクトリは引き続き Clover バージョンに設定され、プロジェクト名には「-clover」が追加されます。「MyProject-clover.war」が Tomcat7 によってホストされている場合、期待どおりに機能しないこともわかりました (ブラウザーで 404 エラーが返されます)。
たとえそれが機能したとしても、統合テストは本番コードに触れないため、テスト対象のWARファイルにCloverインストルメンテーションは必要ありません/必要ありません(src/test/javaの下のすべてのSelenium UIのものです本番コード自体ではなく、ローカルでホストされているページと対話します)。
前述のとおり、これは数百の依存関係と数十のプラグインを含む大規模なプロジェクトです。以下は私の問題に関連していると思いますが、必要に応じてさらに掘り下げることができます (pom ファイル全体を投稿するのは不合理に思えます)。
Clover プラグインの pom 構成は次のとおりです。
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<version>3.1.11</version>
<configuration>
<generateHtml>true</generateHtml>
<generateXml>true</generateXml>
<licenseLocation>${basedir}/src/test/resources/clover.license</licenseLocation>
<targetPercentage>92%</targetPercentage>
<excludes>
<exclude>**/mock/*.java</exclude>
<exclude>**/com/mycompany/somestuff/*.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>generate-clover-report</id>
<phase>test</phase>
<goals>
<goal>instrument</goal>
<goal>clover</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
WAR プラグインの pom 構成は次のとおりです。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<finalName>${project.artifactId}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<!--Implementation-Build>${buildNumber}_${timestamp}</Implementation-Build -->
<Build-Time>${timestamp}</Build-Time>
</manifestEntries>
</archive>
</configuration>
</plugin>
Tomcat7 プラグインの pom 構成は次のとおりです。
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<ajpPort>8009</ajpPort>
<backgroundProcessorDelay>2</backgroundProcessorDelay>
<configurationDir>${project.build.directory}/tomcat7_plugin</configurationDir>
<contextFile>${CATALINA_HOME}/conf/context.xml</contextFile>
<contextReloadable>false</contextReloadable>
<fork>true</fork>
<hostName>localhost</hostName>
<httpsPort>8443</httpsPort>
<ignorePackaging>false</ignorePackaging>
<jarScanAllDirectories>false</jarScanAllDirectories>
<path>/contentmain</path>
<port>8080</port>
<serverXml>${CATALINA_HOME}/conf/server.xml</serverXml>
<tomcatUsers>${CATALINA_HOME}/conf/tomcat-users.xml</tomcatUsers>
<tomcatWebXml>${CATALINA_HOME}/conf/web.xml</tomcatWebXml>
<useNaming>true</useNaming>
<useTestClasspath>true</useTestClasspath>
<update>true</update>
<warDirectory>${project.build.directory}/${project.build.finalName}</warDirectory>
</configuration>
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run-war-only</goal>
</goals>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
</plugin>
「mvn clean install -Dmaven.clover.skip」を実行したときの現在の(望ましい)動作は次のとおりです。
[INFO] --- maven-clover2-plugin:3.1.11:check (generate-clover-report) @ MyProject ---
[INFO]
[INFO] --- maven-dependency-plugin:2.1:unpack (unpack) @ MyProject ---
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes css/*.css and excludes:null
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes scripts/*/*.* and excludes:null
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes images/*.* and excludes:null
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ MyProject ---
[INFO] Packaging webapp
[INFO] Assembling webapp [MyProject] in [mydir/MyProject/target/MyProject]
[INFO] Processing war project
[INFO] Copying webapp resources [mydir/MyProject/src/main/webapp]
[INFO] Webapp assembled in [2019 msecs]
[INFO] Building war: /mydir/MyProject/target/MyProject.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO]
[INFO] >>> maven-source-plugin:2.2.1:jar (default) @ MyProject >>>
[INFO]
[INFO] --- maven-dependency-plugin:2.1:copy (default) @ MyProject ---
[INFO]
[INFO] --- buildnumber-maven-plugin:1.1:create-timestamp (default) @ MyProject ---
[INFO]
[INFO] <<< maven-source-plugin:2.2.1:jar (default) @ MyProject <<<
[INFO]
[INFO] --- maven-source-plugin:2.2.1:jar (default) @ MyProject ---
[INFO] Building jar: /mydir/MyProject/target/MyProject-sources.jar
[INFO]
[INFO] --- tomcat7-maven-plugin:2.2:run-war-only (start-tomcat) @ MyProject ---
[INFO] Running war on http://localhost:8080/contentmain
「mvn clean install」を実行したときの現在の(望ましくない)動作は次のとおりです(maven-war-pluginによってリストされたパスとmaven-source-pluginからの警告メッセージに注意してください:
[INFO] --- maven-clover2-plugin:3.1.11:check (generate-clover-report) @ MyProject ---
[INFO]
[INFO] --- maven-dependency-plugin:2.1:unpack (unpack) @ MyProject ---
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes css/*.css and excludes:null
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes scripts/*/*.* and excludes:null
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes images/*.* and excludes:null
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ MyProject ---
[INFO] Packaging webapp
[INFO] Assembling webapp [MyProject] in [mydir/MyProject/target/clover/MyProject-clover]
[INFO] Processing war project
[INFO] Copying webapp resources [mydir/MyProject/src/main/webapp]
[INFO] Webapp assembled in [1770 msecs]
[INFO] Building war: /mydir/MyProject/target/clover/MyProject-clover.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO]
[INFO] >>> maven-source-plugin:2.2.1:jar (default) @ MyProject >>>
[INFO]
[INFO] --- maven-dependency-plugin:2.1:copy (default) @ MyProject ---
[INFO]
[INFO] --- buildnumber-maven-plugin:1.1:create-timestamp (default) @ MyProject ---
[INFO]
[INFO] <<< maven-source-plugin:2.2.1:jar (default) @ MyProject <<<
[INFO]
[INFO] --- maven-source-plugin:2.2.1:jar (default) @ MyProject ---
[WARNING] NOT adding sources to artifacts with classifier as Maven only supports one classifier per artifact. Current artifact [com.mycompany:MyProject:war:clover:ParentProject-SNAPSHOT] has a [clover] classifier.
[INFO]
[INFO] --- tomcat7-maven-plugin:2.2:run-war-only (start-tomcat) @ MyProject ---
[INFO] Running war on http://localhost:8080/contentmain
のテスト段階で Clover が maven-clover2-plugin:check ゴールの実行を終了した後、 {project.build.directory} と {project.build.finalName} の値が元の値にリセットされるようにするにはどうすればよいですか?分岐したライフサイクル?
Clover、WARプラグイン、およびTomcat7のオンライン マニュアルを参照してみました。Clover によって変更されたビルド変数を元に戻すために使用できる設定については言及されていません。私はいつでも pom ファイルにパスをハードコードすることができますが、より脆弱でない解決策を好みます。