2

別の Web アプリケーションの統合テストを実行する Maven プロジェクトがあります。このアプリケーションは、Tomcat コンテナー内にデプロイされて開始されます。

この設定は「cargo-maven2-plugin」で行います。

 <plugin>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <configuration>
   <wait>false</wait>
   <configuration>
    <type>standalone</type>
    <properties>
     <cargo.hostname>${itest.hostname}</cargo.hostname>
     <cargo.protocol>${itest.protocol}</cargo.protocol>
     <cargo.servlet.port>${itest.port}</cargo.servlet.port>
     <cargo.servlet.uriencoding>UTF-8</cargo.servlet.uriencoding>
     <cargo.jvmargs>-Xmx1024m</cargo.jvmargs>
    </properties>
   </configuration>
   <container>
    <containerId>tomcat6x</containerId>
    <home>${TEST_TOMCAT_HOME}</home>
   </container>
   <deployer>
    <deployables>
     <deployable>
      <groupId>de.apllicationundertest</groupId>
      <artifactId>apllicationundertest</artifactId>
      <type>war</type>
      <!--
       This will test if the app is ready an throw an exception if
       the integration tests start before deployment is finished
      -->
      <pingURL>${itest.protocol}://${itest.hostname}:${itest.port}/${itest.web.context}/main.html 
      </pingURL>
      <pingTimeout>120000</pingTimeout>
      <!--  Setting our context for the integration tests -->
      <properties>
       <context>${itest.web.context}</context>
      </properties>
     </deployable>
    </deployables>
   </deployer>
  </configuration>
  <executions>
   <execution>
    <id>start-container</id>
    <phase>pre-integration-test</phase>
    <goals>
     <goal>start</goal>
     <goal>deploy</goal>
    </goals>
   </execution>
   <execution>
    <id>stop-container</id>
    <phase>post-integration-test</phase>
    <goals>
     <goal>stop</goal>
    </goals>
   </execution>
  </executions>
 </plugin>

テスト中の (Web) アプリケーションは、統合テスト プロジェクトの pom.xml に依存関係として統合されているため、戦争への絶対パスまたは相対パスはありません。

私の問題は、プログラムの実行中に tomcat コンテナーを制御できないことです。私のテスト シナリオでは、いくつかのテストの間にコンテナーの停止と再起動 (およびテスト対象のアプリケーションの再デプロイ) が必要ですが、コンテナーの停止後にまだアクティブなスレッドがあるかどうか、またはコンテナーの要素がまだいくつかあるかどうかを確認するための feキャッシュ内の私のアプリケーション、...

  1. java の外、できれば pom.xml でコンテナーの開始と停止を構成したいと考えています。それは可能ですか?
  2. 特定の単体テストで再起動が必要であることを指定して実行することはできますか? どのように?
4

2 に答える 2

0

pre-integration-testコンテナの起動は段階的に行われるため、可能ではないと思います。再起動したサーバーで特定のテストを実行する必要があるのはなぜですか? 可能であれば、テストを書き直してみてください (クリーンアップを行ってください)。

できればpom.xmlで、Javaの外部でコンテナーの開始と停止を構成したいと考えています。それは可能ですか?

これがほとんど必要ない場合は、個別のテストの構成を専用のプロファイルに入れてみてください。各プロファイルには、貨物と確実な/フェイルセーフ プラグインの構成が含まれます。

特定の単体テストで再起動が必要であることを指定して実行できますか? どのように?

実行するテストを指定できます。確実な/フェイルセーフプラグイン構成を見てください

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.5</version>
    <configuration>
      <includes>
        <include>Sample.java</include>
      </includes>
    </configuration>
    <executions>
      <execution>
        <id>integration-test</id>
        <phase>integration-test</phase>
        <goals>
          <goal>integration-test</goal>
        </goals>
      </execution>
      <execution>
        <id>verify</id>
        <phase>verify</phase>
        <goals>
          <goal>verify</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>
于 2010-02-10T10:50:44.127 に答える
0

できればpom.xmlで、Javaの外部でコンテナーの開始と停止を構成したいと考えています。それは可能ですか?

Maven からできることは、現在行っていることです。つまり、統合前のテスト段階と統合テスト後の段階でそれぞれ貨物を開始および停止します。

特定の単体テストで再起動が必要であることを指定して実行できますか? どのように?

いいえ、これは不可能です。Maven にはこのような粒度がなく、そのためのフックもありません。これが本当に必要な場合は、次の 2 つのオプションがあります。

  • この前の回答で説明したように、Java からコンテナーを制御します。
  • テストを別々の Maven モジュールに入れます (Maven がそれぞれのコンテナーを開始および停止するように)。
于 2010-02-10T14:38:31.100 に答える