2011-03-08 129 views
1

我想在我的一個Maven模塊中啓動一個充當應用程序服務器的sibling maven 3模塊,以針對系統運行集成測試。在集成測試階段執行Maven模塊

我的Maven項目類似於此:

  • 父模塊
    • 模塊A
    • 模塊B

現在我要開始 「模塊A」 在maven的預集成測試階段,然後運行模塊B中包含的所有集成測試。我設法運行i模塊B中的集成測試,但在集成前測試階段沒有找到「光滑」的方式來啓動模塊B.

這樣做的最佳做法是什麼?使用mojo-exec插件?如何配置?使用「髒」的shell腳本並執行模塊A的mvn運行?

編輯

我不想開始預集成測試階段的應用程序服務器,但要運行一個Maven模塊(其本身開始的魔力,EXEC-插件)。運行意味着開始打包(工作)模塊的主類!

+0

的「最佳做法」是對模塊本身的模塊測試。 – 2011-03-08 17:02:44

回答

5

儘量使用綁定到安裝階段的maven-EXEC-插件的Java的目標:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.2.1</version> 
    <executions> 
     <execution> 
     <id>start-app</id> 
     <phase>install</phase> 
     <goals> 
      <goal>java</goal> 
     </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <mainClass>com.example.Main</mainClass> 
     <arguments> 
     <argument>argument1</argument> 
     ... 
     </arguments> 
     <systemProperties> 
     <systemProperty> 
      <key>myproperty</key> 
      <value>myvalue</value> 
     </systemProperty> 
     ... 
     </systemProperties> 
    </configuration> 
    </plugin> 
-1

首先,您應該將集成測試放到單個模塊中讓我們假設您使用模塊A,而不是您應該在同一模塊上運行集成測試階段,而不是在不同的模塊中。

您可以使用cargo-plugin在預集成測試階段爲應用服務器啓動一個啓動程序,通過maven-failsafe插件運行集成測試,並在集成後階段關閉應用服務器,通過貨物插件進行測試。 下面是配置cargo plugin啓動/停止Tomcat服務器的摘要,但貨物還支持JBoss的,Glassfish的等

<plugin> 
     <groupId>org.codehaus.cargo</groupId> 
     <artifactId>cargo-maven2-plugin</artifactId> 
     <version>1.0.5</version> 
     <configuration> 
     <wait>false</wait> 
     <container> 
      <containerId>tomcat${tomcat.major}x</containerId> 
      <zipUrlInstaller> 
      <url>http://www.apache.org/dist/tomcat/tomcat-${tomcat.major}/v${tomcat.version}/bin/apache-tomcat-${tomcat.version}.tar.gz</url> 
      <installDir>${installDir}</installDir> 
      </zipUrlInstaller> 
      <output>${project.build.directory}/tomcat${tomcat.major}x.log</output> 
      <log>${project.build.directory}/cargo.log</log> 
     </container> 
     <configuration> 
      <home>${project.build.directory}/tomcat-${tomcat.version}/container</home> 
      <properties> 
      <cargo.logging>high</cargo.logging> 
      <cargo.servlet.port>9080</cargo.servlet.port> 
      <cargo.jvmargs>-DHUDSON_HOME=${project.build.directory}/hudson-storage</cargo.jvmargs> 
      </properties> 
     </configuration> 
     </configuration> 
     <executions> 
     <execution> 
      <id>start-container</id> 
      <phase>pre-integration-test</phase> 
      <goals> 
      <goal>start</goal> 
      <goal>deploy</goal> 
      </goals> 
      <configuration> 
      <deployer> 
       <deployables> 
       <deployable> 
        <groupId>org.jvnet.hudson.main</groupId> 
        <artifactId>hudson-war</artifactId> 
        <type>war</type> 
        <pingURL>http://localhost:9080/hudson</pingURL> 
        <pingTimeout>60000</pingTimeout> 
        <properties> 
        <context>hudson</context> 
        </properties> 
       </deployable> 
       </deployables> 
      </deployer> 
      </configuration> 
     </execution> 
     <execution> 
      <id>stop-container</id> 
      <phase>post-integration-test</phase> 
      <goals> 
      <goal>stop</goal> 
      </goals> 
     </execution> 
     </executions> 
    </plugin> 

下面的代碼片段爲您提供瞭如何使用maven-surefire插件和編譯器的印象插件:在這種情況下,重要的是名稱的集成測試(如XYZ * IT.jav)

<plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>2.3.2</version> 
     <executions> 
     <execution> 
      <goals> 
      <goal>testCompile</goal> 
      </goals> 
     </execution> 
     </executions> 
    </plugin> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-failsafe-plugin</artifactId> 
     <version>2.6</version> 
     <executions> 
     <execution> 
      <id>integration-test</id> 
      <goals> 
      <goal>integration-test</goal> 
      </goals> 
     </execution> 
     <execution> 
      <id>verify</id> 
      <goals> 
      <goal>verify</goal> 
      </goals> 
     </execution> 
     </executions> 
    </plugin> 

你不需要Exec插件等或shell腳本在運行Maven的集成測試。

+0

感謝您的回答,但整個集成測試設置與故障安全工作正常。我只想在同級maven模塊中啓動一個「主要方法」。 – saintedlama 2011-03-08 16:29:13

相關問題