3

我試圖運行在單獨的Maven協議集成測試,所以我需要做的是在下面的步驟:如何在運行集成測試之前啓動tomcat?

  1. 運行Tomcat服務器。
  2. 運行Selenium服務器。
  3. 運行集成測試。

我運行集成測試如下:

mvn install -Pit 

,但發生的事情是集成測試第一次運行服務器開始之前,這將導致測試失敗,下面是我的配置:

<profile> 
      <id>it</id> 
      <build> 
      <plugins> 


     <plugin> 

      <groupId>org.codehaus.cargo</groupId> 
      <artifactId>cargo-maven2-plugin</artifactId> 
      <version>1.1.4</version> 
      <configuration> 

       <wait>false</wait> 
       <container> 
       <containerId>tomcat7x</containerId> 
       <home>${env.CATALINA_HOME}</home> 
       <timeout>300000</timeout>     
       </container> 

       <configuration> 
       <type>standalone</type> 
       <home>target/tomcat7x</home> 
       <properties> 
        <cargo.jvmargs>-XX:PermSize=256m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled</cargo.jvmargs> 
       </properties> 
       </configuration> 



      </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> 



     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>selenium-maven-plugin</artifactId> 
       <executions> 
        <execution> 
        <id>start</id> 
        <phase>pre-integration-test</phase> 
         <goals> 
          <goal>start-server</goal> 
         </goals> 
        <configuration> 
         <background>true</background> 
         <logOutput>true</logOutput> 
        </configuration> 
       </execution> 

       <execution> 
       <id>stop</id> 
       <phase>post-integration-test</phase> 
         <goals> 
          <goal>stop-server</goal> 
         </goals> 
       </execution> 
      </executions> 
    </plugin> 


      <plugin> 

       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.8</version> 

       <configuration> 
        <junitArtifactName> 
        org.junit:com.springsource.org.junit 
        </junitArtifactName> 
        <excludes> 

         <exclude>**/unit/*Test.java</exclude> 
        </excludes> 
       </configuration> 


       <executions> 
        <execution> 

        <id>integration-tests</id> 
        <phase>integration-test</phase> 
         <goals> 
          <goal>test</goal> 
         </goals> 
        <configuration> 
        <skip>false</skip> 
        <excludes> 
         <exclude>none</exclude> 
        </excludes> 

        <includes> 
         <include>**/integration/*Test.java</include> 
        </includes> 
        </configuration> 
        </execution> 
      </executions> 

       </plugin> 
       </plugins> 
      </build> 

      <activation> 
       <property> 
       <name>it</name> 
       </property> 
      </activation> 

     </profile> 

請告訴我的配置有什麼問題。

UPDATE:Maven的日誌

[INFO] Scanning for projects... 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building My APP 
[INFO] task-segment: [install] 
[INFO] ------------------------------------------------------------------------ 
[INFO] [jaxws:wsimport {execution: default}] 
[debug] execute contextualize 
[INFO] [resources:resources {execution: default-resources}] 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 7 resources 
[INFO] [compiler:compile {execution: default-compile}] 
[INFO] Nothing to compile - all classes are up to date 
[debug] execute contextualize 
[INFO] [resources:testResources {execution: default-testResources}] 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 5 resources 
[INFO] [compiler:testCompile {execution: default-testCompile}] 
[INFO] Nothing to compile - all classes are up to date 
[INFO] [surefire:test {execution: default-test}] 
[INFO] Surefire report directory: C:\Workspace\MyAPP\target\surefire-reports 

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 
Running integration.MyTest 

UPDATE3

它工作得很好刪除與以下新老交替神火插件後:

<plugin> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <executions> 

        <execution> 
         <id>default-test</id>         
         <configuration> 
          <skipTests>true</skipTests> 
         </configuration> 
        </execution> 

        <execution> 
         <id>surefire-it</id> 
         <phase>integration-test</phase> 
         <goals> 
          <goal>test</goal> 
         </goals> 
         <configuration> 
          <includes> 
           <include>**/integration/*Test.java</include> 
          </includes> 
          <skipTests>false</skipTests> 
         </configuration> 
        </execution> 
       </executions> 
       <configuration> 
        <argLine>-Xms256M -Xmx768M -XX:MaxPermSize=256M</argLine> 
       </configuration> 
      </plugin> 

,但有一個問題與貨物插件,是它部署戰爭文件,然後運行整合ation測試,並且在調用任何測試方法之前,它會取消部署war文件?

+1

你可以發佈maven run的日誌嗎?想知道如果surefire運行'測試'的目標和失敗,而不是在'集成測試'目標失敗... – Raghuram 2012-01-17 12:04:35

+1

你也可以看看maven failsafe插件(http://maven.apache.org/plugins/ maven-failsafe-plugin /)運行集成測試 – Raghuram 2012-01-17 12:05:12

+1

@Raghuram,添加了日誌,你是說我應該使用故障安全並刪除surfire?如果是這樣,故障安全所需的最低配置是多少? – 2012-01-17 12:13:35

回答

2

根據日誌,很明顯失敗是因爲surefire正在運行test階段的集成測試,而不是integration-test階段。

This link說,如何使用surefire只進行集成測試。

This documentation給出了有關Maven和集成測試最佳實踐的更多見解。

+0

請看看我的第三次更新。 – 2012-01-17 13:01:49

+0

我會把新問題放在單獨的主題中。 – 2012-01-17 13:07:22

相關問題