我有一个由多个 maven war 项目组成的应用程序。
我有另一个 Maven 项目,它使用 org.springframework.web.client.RestTemplate 调用针对手动启动的 tomcat 部署的多 war 应用程序运行 JUnit 集成测试。
但是,我希望我的集成测试项目在运行我的测试之前真正启动我的多 war 应用程序(整个套件的持续时间一次)...在 spring-boot 中!
在我的集成测试项目中,我希望能够将所有 war 项目作为一个 spring-boot 应用程序一起运行,每个项目都有自己的上下文路径(例如,localhost:8080/a 用于项目“a”,localhost: 8080/b for project 'b', etc.),并且没有改变原始的 war 项目((还)不支持 spring-boot)。如果我不能让这些项目在不更改它们的情况下从我的 spring-boot 集成测试项目运行,那么我至少想尽量减少打包 war 文件中 spring-boot 依赖项和配置的使用......尽可能多.
我能够让我的集成测试项目依赖于单个 war 项目,启动它并针对它运行测试......但是我没有成功让两个 war 项目在单独的 contextPaths 下在 spring-boot 中一起运行。
欢迎提出任何建议!
以下是我用来整合这些内容的一些资源:
(Spring-boot 文档)http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html
(关于为测试套件启动一次 spring 应用程序的博文)http://www.nurkiewicz.com/2010/12/speeding-up-spring-integration-tests.html
(将 war 文件作为依赖项包含在集成测试项目 pom 中的建议)http://eureka.ykyuen.info/2009/10/30/maven-dependency-on-jarwar-package/
最佳答案
按照 Andy 的建议,我使用了 Tomcat7 Maven 插件,它工作得很好。 Jetty Maven 插件是另一种选择(并且在 IMO 中有更好的文档记录),尽管我找不到避免必须为我的 WAR 文件提供“路径”的方法。 Tomcat7 Maven 插件让我可以从我的本地 .m2 存储库加载我的 WAR。我还应该说以下链接也很有帮助...
- http://cupofjava.de/blog/2013/02/05/integration-tests-with-maven-and-tomcat/
- https://stackoverflow.com/a/16936585/1098564
这是我的集成测试项目 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>
关于java - Spring Boot多war应用集成测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26149711/