【发布时间】:2011-06-29 22:33:39
【问题描述】:
我正在使用 maven 和 maven-failsafe-plugin 在集成测试生命周期阶段启动码头。然后,我对正在运行的 webapp 执行一些 (*IT.java) junit 测试。这按预期工作。
但是,我想为我的集成测试连接到一个测试数据库。我将其网址存储在
${basedir}/src/test/resources/jdbc.properties
jetty 插件运行时(jetty:run),它使用
${basedir}/src/main/resources/jdbc.propertes
相反。我尝试通过 classesDirectory 属性重新配置码头插件以使用
${project.build.testOutputDirectory}
但 test-classes 目录缺少我实际编译的项目类,以及存储在其中的资源
${basedir}/src/main/resources
注意:surefire 将测试资源添加到类路径,然后是主要资源,这样在两者中找到的任何内容都将使用测试版本,因为它首先在类路径中找到。
关于如何正确设置的任何想法?
谢谢!
编辑:
好吧,码头插件上似乎有configuration properties来处理这个问题:
- testClassesDirectory : 包含生成的测试类的目录。
- useTestClasspath : 如果为 true,则 test 的和依赖项将首先放在运行时类路径中。
不幸的是,它们不起作用。
这是我的 pom.xml 的相关部分:
<testResources> <testResource> <filtering>true</filtering> <directory>src/test/resources</directory> </testResource> </testResources> <plugins> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.26</version> <configuration> <contextPath>/</contextPath> <stopPort>8005</stopPort> <stopKey>STOP</stopKey> </configuration> <executions> <execution> <id>start-jetty</id> <phase>pre-integration-test</phase> <goals> <goal>run</goal> </goals> <configuration> <daemon>true</daemon> <useTestClasspath>true</useTestClasspath> <testClassesDirectory>${project.build.testOutputDirectory}</testClassesDirectory> </configuration> </execution> <execution> <id>stop-jetty</id> <phase>post-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-failsafe-plugin</artifactId> <version>2.6</version> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> </execution> </executions> <configuration> <useFile>false</useFile> </configuration> </plugin>
【问题讨论】:
-
你能添加你的POM的相关部分吗?
-
谢谢,这对我帮助很大。需要注意的一件事是,我试图使用 run-exploded 目标(根据故障安全文档),它不支持 useTestClassPath 或 testClassesDirectory。
标签: java maven integration-testing surefire maven-jetty-plugin