sdo*_*see 7 java junit spring maven spring-boot
我有一个由多个maven战争项目组成的应用程序.
我有另一个maven项目,使用org.springframework.web.client.RestTemplate调用对手动启动的tomcat部署的多战应用程序运行JUnit集成测试.
但是,我希望我的集成测试项目在运行我的测试之前实际启动我的多战应用程序(一次是整个套件的持续时间)...在spring-boot中!
从我的集成测试项目开始,我希望能够将所有war项目作为spring-boot应用程序一起运行,每个应用程序都有自己的contextPaths(例如localhost:8080/a用于项目'a',localhost:8080/b对于项目'b'等),并且不更改原始的war项目(尚未启动Spring-boot).如果我不能在spring-boot中从我的集成测试项目中运行这些项目而不更改它们那么我至少希望尽可能减少在打包的war文件中使用spring-boot依赖项和配置...尽可能.
我能够让我的集成测试项目依赖于单个war项目,启动它并针对它运行测试......但是我没有成功在spring-boot下在单独的contextPaths下运行两个war项目.
欢迎大家提出意见!
以下是我用过的一些资源:
(Spring-boot文档)http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html
(关于测试套件启动弹簧应用程序的博客文章)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.我还应该说以下链接也很有用......
这是我的集成测试项目的一部分...
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2688 次 |
| 最近记录: |