Maven将多次战争部署到嵌入式服务器以进行集成测试 [英] Maven deploy multiple wars to embedded server for integration tests

查看:92
本文介绍了Maven将多次战争部署到嵌入式服务器以进行集成测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于在嵌入式服务器上运行Maven War项目进行自己的集成测试,我没有任何问题,但是现在我需要运行多次Wars并从其他项目进行测试.

I have had no issue running a maven war project on an embedded server for its own integration tests, but now I need to run multiple wars and test from a different project.

我想设置以下情况...

I would like to setup the following scenario...

我在本地工作区中有两个Maven战争项目,分别称为War1和War2.我想要第三个Maven项目WarIntegration,该项目仅包含集成测试并执行以下操作:

I have two Maven war projects in my local workspace called War1 and War2. I would like to have a 3rd Maven project, WarIntegration, that contains only integration tests and does the following:

  1. 打包War1
  2. 打包War2
  3. 启动嵌入式服务器
  4. 将两次战争部署到同一台嵌入式服务器
  5. 运行WarIntegration中包含的集成测试(它将对War1和War2进行http调用)
  6. 停止嵌入式服务器

这可能吗?哪些插件设置可以实现此目的? WarIntergration应该是什么样的项目(打包)? War1和War2应该是WarIntegration还是依赖项中的模块?是否可以将所有配置都添加到WarIntegration项目中,或者必须将其散布到整个项目中?

Is this possible? What plugin setup will achieve this? What kind of project should WarIntergration be (packaging)? Should War1 and War2 be modules in WarIntegration or dependencies? Can all of the configuration be aded to the WarIntegration project or would it have to be spread across the projects?

这类似于此问题,除了我们必须使用由项目启动和停止的嵌入式服务器(可能在运行验证时),并且我们需要一个单独的项目来进行集成测试:

This is similar to this question, except we must use an embedded server that is started and stopped by the project (probably when we run verify) and we need a separate project for integration tests: I have a multi-module Maven 2 POM that has two WARs, how can I configure it to deploy both wars prior to running tests?

推荐答案

我能够使用cargo-maven2-plugin实现此目的.

I was able to achieve this using the cargo-maven2-plugin.

以下是所有感兴趣的pom相关内容...

Here are the relevant pieces of the pom for anyone who is interested...

...
<groupId>com.test</groupId>
<artifactId>webapp-integration</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
...
<dependencies>
        ...
        <dependency>
            <artifactId>webapp1</artifactId>
            <groupId>com.test</groupId>
            <version>1.0</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>webapp2</groupId>
            <artifactId>com.test</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>war</type>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <version>1.2.2</version>
                <configuration>
                    <container>
                        <containerId>jetty6x</containerId>
                        <type>embedded</type>
                    </container>
                    <configuration>
                        <type>standalone</type>
                        <properties>
                            <cargo.servlet.port>8085</cargo.servlet.port>
                        </properties>
                        <deployables>
                            <deployable>
                                <artifactId>webapp1</artifactId>
                                <groupId>com.test</groupId>
                                <type>war</type>
                                <pingURL>http://localhost:8085/testapp/</pingURL>
                                <properties>
                                    <context>testapp</context>
                                </properties>
                            </deployable>
                            <deployable>
                                <artifactId>webapp2</artifactId>
                                <groupId>com.test</groupId>
                                <type>war</type>
                                <pingURL>http://localhost:8085/testapp2/</pingURL>
                                <properties>
                                    <context>testapp2</context>
                                </properties>
                            </deployable>
                        </deployables>
                    </configuration>
                </configuration>
                <executions>
                    <execution>
                        <id>start-server</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-server</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.12</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.surefire</groupId>
                        <artifactId>surefire-junit47</artifactId>
                        <version>2.12</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <groups>com.test.integration.IntegrationTestMarker</groups>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <configuration>
                            <includes>
                                <include>**/*.class</include>
                            </includes>
                            <skipTests>false</skipTests>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

这篇关于Maven将多次战争部署到嵌入式服务器以进行集成测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆