2012-02-10 11 views
7

私はクライアント/サーバアプリケーションをテストし、Mavenを使ってbuild/test/deployを処理しようとしています。アプリケーションをテストするために、私のことを行う必要がありますexec-maven-pluginを単一のフェーズで複数回実行する

  1. は、起動コマンドキックオフ(サービスを起動するために)、
  2. テスト(maven-を実行
  3. 、(サーバーをインストールする)インストーラスクリプトを実行しますサービスを停止し、
  4. サービスをアンインストールします。

手順1,2,4および5では、maven-exec-pluginを使用します。ステップ3では、maven-surefire-pluginを使用します。

問題は、これらのステップの5つすべてが「テスト」フェーズで発生することです。 Mavenはプラグインが特定の順序で実行されるようにします。 exec-pluginは、複数のエントリを使用して複数回実行できます。問題は、4つのexec-plugin実行の途中でsurefire-pluginを使用する必要があることです。

プラグインと実行の構造を知っている人はいますか?

+0

私が思うに、あなたはそれを最適化することはできません。 'maven-surefire-plugin' +' maven-surefire-plugin' + 'maven-exec-plugin'はあなたがそれを行うための唯一の方法です(あなたのためにそれを組み合わせるあなた自身のmavenプラグインを書くのに十分な)。 –

答えて

4

あなたがしようとしているのは、単体テストよりも統合テストのほうがよく聞こえます。

  • pre-integration-test:統合テストが実行される前に必要なアクションを実行するこのユースケースについてdefault maven lifecycleは、統合テストに関連する3つのフェーズがあります。これには、必要な環境の設定などが含まれます。
  • integration-test:統合テストを実行できる環境に、必要に応じてパッケージを処理して展開します。
  • post-integration-test:統合テストが実行された後に必要なアクションを実行します。これには、環境の清掃も含まれます。

surefireプラグインは、通常、testフェーズで実行されますが、別のフェーズで実行するように再設定できます。手順1 + 2はpre-integration-testで実行するように構成できますが、手順4 + 5はpost-integration-testで実行する必要があります。

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <!-- Skip execution in test phase and execute in integration-test phase instead --> 
    <configuration> 
     <skip>true</skip> 
    </configuration> 
    <executions> 
     <execution> 
      <id>surefire-it</id> 
      <phase>integration-test</phase> 
      <goals> 
       <goal>test</goal> 
      </goals> 
      <configuration> 
       <skip>false</skip> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 
+0

これは多かれ少なかれ私が行ったルートです。 Mavenにプリテストとテスト後の段階がない理由はわかりませんが、統合テスト段階で十分でしょう。 – SlimyTadpole

10

これは、私がexecとfailsafeプラグインを設定した方法です。私はフェイルセーフを使用しています。確実に再構成するのではなく、確実にテストフェーズにある他のテストが実行されているからです。これは、統合前のテスト段階でステップ1と2を実行します(同じフェーズで実行された複数の実行が指定された順序で実行されます)。統合テストのフェーズでテストを実行してから、ステップ3と4でクリーンアップします。ポスト統合テスト段階。

(注:私は本当のインストールとクリーンアップのコマンドの代わりに、エコーコマンドを持っている)

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-failsafe-plugin</artifactId> 
    <executions> 
     <execution> 
      <goals> 
       <goal>integration-test</goal> 
      </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <forkMode>always</forkMode> 
    </configuration> 
</plugin> 

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <executions> 
     <execution> 
      <id>step1</id> 
      <goals> 
       <goal>exec</goal> 
      </goals> 
      <phase>pre-integration-test</phase> 
      <configuration> 
       <executable>echo</executable> 
       <arguments> 
        <argument>foo</argument> 
       </arguments> 
      </configuration> 
     </execution> 
     <execution> 
      <id>step2</id> 
      <goals> 
       <goal>exec</goal> 
      </goals> 
      <phase>pre-integration-test</phase> 
      <configuration> 
       <executable>echo</executable> 
       <arguments> 
        <argument>bar</argument> 
       </arguments> 
      </configuration> 
     </execution> 
     <execution> 
      <id>step3</id> 
      <goals> 
       <goal>exec</goal> 
      </goals> 
      <phase>post-integration-test</phase> 
      <configuration> 
       <executable>echo</executable> 
       <arguments> 
        <argument>baz</argument> 
       </arguments> 
      </configuration> 
     </execution> 
     <execution> 
      <id>step4</id> 
      <goals> 
       <goal>exec</goal> 
      </goals> 
      <phase>post-integration-test</phase> 
      <configuration> 
       <executable>echo</executable> 
       <arguments> 
        <argument>woot</argument> 
       </arguments> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 
+0

これはどのプラグインのバージョンですか?バージョン1.2.1での実行中にで実行するプラグインを取得できません – avanderw