简体   繁体   English

Spring Boot中多战应用的集成测试

[英]Integration testing of multi-war application in Spring Boot

I have an application composed of multiple maven war projects. 我有一个由多个maven战争项目组成的应用程序。

I have another maven project that runs JUnit integration tests against the manually-started tomcat-deployed multi-war application using org.springframework.web.client.RestTemplate calls. 我有另一个maven项目,使用org.springframework.web.client.RestTemplate调用对手动启动的tomcat部署的多战应用程序运行JUnit集成测试。

However, I'd like my integration test project to actually start my multi-war application (once for the duration of the entire suite) before it runs my tests...in spring-boot! 但是,我希望我的集成测试项目在运行我的测试之前实际启动我的多战应用程序(在整个套件的持续时间内)...在spring-boot中!

From my integration test project, I'd like to be able to run all the war projects together as a spring-boot application, each with their own contextPaths (eg localhost:8080/a for project 'a', localhost:8080/b for project 'b', etc. ), and without changing the original war projects (that are not (yet) spring-boot aware). 从我的集成测试项目开始,我希望能够将所有war项目作为spring-boot应用程序一起运行,每个应用程序都有自己的contextPaths(例如localhost:8080 / a用于项目'a',localhost:8080 / b对于项目'b'等),并且不更改原始的war项目(尚未启动Spring-boot)。 If I can't make these projects run from my integration test project in spring-boot without changing them then I'd at least like to minimize the use of spring-boot dependencies and configuration in packaged war files...as much as possible. 如果我不能在spring-boot中从我的集成测试项目中运行这些项目而不更改它们那么我至少希望尽可能减少在打包的war文件中使用spring-boot依赖项和配置...尽可能。

I was able to get my integration test project to depend on a single war project, start it up and run tests against it...but I was unsuccessful getting two war projects running together in spring-boot under separate contextPaths. 我能够让我的集成测试项目依赖于单个war项目,启动它并针对它运行测试......但是我没有成功在spring-boot下在单独的contextPaths下运行两个war项目。

Any suggestions would be welcome! 欢迎大家提出意见!

Here are some of the resources I've been using to put this together: 以下是我用过的一些资源:

As per Andy's suggestion, I went with the Tomcat7 Maven Plugin and it worked just fine. 根据Andy的建议,我使用了Tomcat7 Maven插件,它运行得很好。 The Jetty Maven Plugin was another option (and better documented IMO) although I couldn't find a way to avoid having to provide a "path" to my WAR files. Jetty Maven插件是另一种选择(并且更好地记录了IMO),虽然我找不到一种方法来避免必须为我的WAR文件提供“路径”。 The Tomcat7 Maven Plugin, let me load up my WARs from my local .m2 repository. Tomcat7 Maven插件,让我从我当地的.m2存储库加载我的WAR。 I should also say that the following links were helpful as well... 我还应该说以下链接也很有用......

Here's part of my integration test project pom... 这是我的集成测试项目的一部分...

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <includes>
                    <include>**/*Test*</include>
                </includes>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <path>/</path>
                <webapps>
                    <webapp>
                        <groupId>com.mycompany</groupId>
                        <artifactId>app1</artifactId>
                        <version>${project.version}</version>
                        <type>war</type>
                        <asWebapp>true</asWebapp>
                    </webapp>
                    <webapp>
                        <groupId>com.mycompany</groupId>
                        <artifactId>app2</artifactId>
                        <version>${project.version}</version>
                        <type>war</type>
                        <asWebapp>true</asWebapp>
                    </webapp>
                </webapps>
            </configuration>
            <executions>
                <execution>
                    <id>start-tomcat</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>run-war</goal>
                    </goals>
                    <configuration>
                        <fork>true</fork>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-tomcat</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>shutdown</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM