【问题标题】:How to start tomcat before running integration test?如何在运行集成测试之前启动tomcat?
【发布时间】:2012-01-17 11:01:23
【问题描述】:

我正在尝试在单独的 Maven 配置文件中运行集成测试,所以我需要按以下步骤进行:

  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>

请告知我的配置有什么问题。

更新: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

用以下内容替换旧的surefire插件后它工作正常:

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

但是cargo插件有一个问题,它是部署war文件然后运行集成测试,然后在调用任何测试方法之前取消部署war文件??

【问题讨论】:

  • 可以贴一下maven运行的日志吗?想知道万能是否正在运行 test 目标并失败,而不是在 integration-test 目标中失败......
  • 您可能还想查看 maven 故障安全插件 (maven.apache.org/plugins/maven-failsafe-plugin) 以运行集成测试
  • @Raghuram,添加了日志,您的意思是我应该使用故障保护并删除 surfire 吗?如果是这样,故障安全所需的最低配置是多少?

标签: jakarta-ee maven continuous-integration automated-tests integration-testing


【解决方案1】:

根据日志,很明显失败是因为surefire在test阶段而不是integration-test阶段运行集成测试。

This link 说,如何仅将surefire 用于集成测试。

This documentation 提供有关 maven 和集成测试的最佳实践的更多见解。

【讨论】:

  • 我想我会将新问题放在单独的主题中。
猜你喜欢
  • 2014-10-10
  • 2013-03-20
  • 1970-01-01
  • 1970-01-01
  • 2013-04-08
  • 1970-01-01
  • 2018-01-14
  • 2014-01-12
  • 2020-01-02
相关资源
最近更新 更多